View Only
  • 1.  Select name

    Posted Oct 01, 2011 07:48 AM


    When i am running get-cluster | select name

    I get this output:


    When i put

    $clusters = get-cluster | select Name

    Write-host "$clusters"

    I get this output:


    Is it posible to get "pretty" output when I use it in a script?

  • 2.  RE: Select name
    Best Answer

    Posted Oct 01, 2011 08:34 AM

    The Select-Object cmdlet returns an array of PSCustomObjects objects.

    That's why you see the '@{...}', which indicates an array.

    And the 'Name=Name_of_Cluster', which is the property in the PSCustomObjects object.

    You want the value of Name property in your output, not the complete object.

    You could do

    $clusters = get-cluster | select Name 
    | %{$_.Name}

    or perhaps even better, don't use the Select-Object when you store the objects internally.

    $clusters = get-cluster 
    | %{$_.Name}

  • 3.  RE: Select name

    Posted Oct 01, 2011 10:00 AM

    Just was I was looking for, thank you for the fast response.