Automation

 View Only
  • 1.  get-vmhost property

    Posted Jun 23, 2011 04:21 PM

    If I run

    get-datacenter | Get-VMHost | select Name, Parent

    I get ouput like

    Name                                                       Parent                                               
    ----                                                            ------                                               

    svr1.example.com                                   Cluster 1

    svr2.example.com                                   Cluster 1

    svr3.example.com                                   Cluster 1

    svr4.example.com                                   host

    This is because my layout is as follows

    Datacentre 1

    -Cluster 1

    --svr1

    --svr2

    --svr3

    -svr4

    svr4 is a standalone system in that datacenter.

    Running

    get-datacenter | Get-VMHost | ?{ $_.Parent -eq "host" }

    Returns nothing though I would expect it to return "svr4"

    get-datacenter | Get-VMHost | ?{ $_.Parent -ne "host" }

    Returns everything.

    Any Ideas?

    Thanks in advance



  • 2.  RE: get-vmhost property
    Best Answer

    Posted Jun 24, 2011 05:38 AM

    The Parent property points to a Folder object, not a string with the name of the parent.

    If you do

    get-datacenter | Get-VMHost | ?{ $_.Parent.Name -eq "host" }

    you should see the result you expect.

    In the Folder object there is a Name property (which holds a string) that you can use in the where-clause.



  • 3.  RE: get-vmhost property

    Posted Jun 24, 2011 08:37 AM

    Perfect, thanks.

    Is there away to see what is returned (i.e. object or string) ?

    Ryan



  • 4.  RE: get-vmhost property

    Posted Jun 24, 2011 08:43 AM

    Yes, you can use the Get-Member cmdlet like this

    Get-Datacenter | Get-VMhost | Get-Member

    or the GetType function

    Get-Datacenter | Get-VMhost | %{$_.Parent.GetType()}

    Get-Datacenter | Get-VMhost | %{$_.Parent.Name.GetType()}



  • 5.  RE: get-vmhost property

    Posted Jun 24, 2011 08:48 AM

    Thanks,

    it seems powershell takes a wee bit of getting used to.

    Ryan



  • 6.  RE: get-vmhost property

    Posted Jun 24, 2011 08:51 AM

    Once you get past the step of thinking in "objects that have properties that pass through a pipeline", it becomes quite easy.

    You'll start to appreciate it's ease of use and you will love it  :smileyhappy: