« Previous Next »

Thread: Cannot manipulate get-childitem variable

Last post 09-25-2009 1:58 PM by JeongHwan. 1 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (2 items)

Sort Posts:

  • 09-25-2009, 7:12 AM

    • rkr31
    • Top 200 Contributor
    • Joined on 05-01-2007, 6:15 AM
    • Posts 30

    Cannot manipulate get-childitem variable

    Hi

    I think that this is probably powershell specific rather than just to do with IIS, but im hoping that you will be able to help anyhow.  I have several sites running on iis.  Site id's are numeric and in order (the first site id is 0001, second is 0002 etc...).  I want to return the last site id, increment it and then add the next site in sequence (so if the last site was 0023 then i will get that value, add 1 and then add the next site with an id of 0024).

    The line below gets the last id, but if i try to manipulate the data in $test it gives me all sorts of oddness.  Im guessing that it's just because it's not a string variable, but to be honest im not really sure.  Any ideas? 

    $test = Get-ChildItem IIS:\Sites|select-object -last 1|format-list id

  • 09-25-2009, 1:58 PM In reply to

    • JeongHwan
    • Top 150 Contributor
    • Joined on 12-14-2004, 11:43 AM
    • Redmond, WA
    • Posts 33

    Re: Cannot manipulate get-childitem variable

    You cannot use the object value as a site id value as you thought. :-)

    Here is one of the way to use the ID as a number value.

    $test = (Get-ChildItem IIS:\Sites|select-object -last 1).id 

     

    FYI, here is the way to check the data type.

    PS IIS:\sites> (Get-ChildItem IIS:\Sites|select-object -last 1|format-list id | select id).gettype()

    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     Object[]                                 System.Array


    PS IIS:\sites> ((Get-ChildItem IIS:\Sites|select-object -last 1).id).gettype()

    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     Int64                                    System.ValueType

    Jeong Hwan Kim
Page 1 of 1 (2 items)
Microsoft Communities