none
Unable to use .(propertyNameHere) all the sudden RRS feed

  • Question

  • So there I am testing a script using a typical $service = get-service followed by $service.name and nothing.  I get confused and hit $service and there is everything.  I try a few different commands and get the same result.  For some reason I cannot use .property to get anything on any command I try.  No errors no warnings nothing.

    Dislaimer 1:As usual I could be way off so no playing like I'm Frankenstein. Disclaimer 2: my Speeling and proofing skills are teh fail

    Monday, March 31, 2014 8:32 PM

Answers

All replies

  • So what's your question?


    -- Bill Stewart [Bill_Stewart]

    Monday, March 31, 2014 8:39 PM
    Moderator
  • Are you trying this command on PowerShell 2.0, by chance?  The "Member Enumeration" feature was new to PowerShell 3.0, and that's what allows you to do something like $service.Name when $service is an array containing multiple objects.  In PowerShell 2.0, you would have had to do something like this instead:

    $service | Select-Object -ExpandProperty Name

    Monday, March 31, 2014 8:53 PM
  • so here is the full example:

    $DatacenterName = Get-datacenter
    $menu = @{}
    For ($i=1;$i -le $DatacenterName.count; $i++){
        Write-host "$i. $($ClusterName[$i-1].name)"
        $menu.Add($i,($DatacenterName[$i-1].name))
        }

    [int]$ans = Read-Host 'Enter selection'
    $DatacenterSelection = $menu.Item($ans)

    Write-host ""
    Write-Host "$DatacenterSelection selected."
    Write-host ""

    This was working just fine until about 12:15 then all the sudden i started getting:

    21.
    Cannot index into a null array.
    At line:2 char:14
    + $ClusterName[ <<<< $i-1].name
        + CategoryInfo          : InvalidOperation: (21:Int32) [], RuntimeException
        + FullyQualifiedErrorId : NullArray

    however when I select a number the proper name displays

    I did however open another script that performs the same action just no using get-datacenter and it works fine.  I was looking for ideas.


    Dislaimer 1:As usual I could be way off so no playing like I'm Frankenstein. Disclaimer 2: my Speeling and proofing skills are teh fail

    Monday, March 31, 2014 9:20 PM
    • Marked as answer by Liam Silva Monday, March 31, 2014 11:55 PM
    Monday, March 31, 2014 10:19 PM
  • wow did i miss that completely

    Dislaimer 1:As usual I could be way off so no playing like I'm Frankenstein. Disclaimer 2: my Speeling and proofing skills are teh fail

    Monday, March 31, 2014 11:56 PM
  • wow did i miss that completely

    =]

    Sometimes all that you need is a fresh pair of eyes.


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    Tuesday, April 1, 2014 12:45 AM
  • Hey - I though Frankenstein had a fresh pair of eyes...and a brain.. and a heart....

    ¯\_(ツ)_/¯

    Tuesday, April 1, 2014 4:39 AM