VMware Cloud Community
vandreytrindade
Enthusiast
Enthusiast
Jump to solution

Help to show VMHost name on a script

Hi,

Beginners question...

Using this command: Get-VMHost | Get-VMHostStartPolicy

I get this result:

VMHost                    Enabled  StartDelay StopAction StopDelay  WaitForHeartbeat
------                    -------  ---------- ---------- ---------  ----------------
HostSystem-ha-host        True    120        GuestSh... 120        False
HostSystem-ha-host        True    120        GuestSh... 120        True
HostSystem-ha-host        True    120        GuestSh... 120        False

How to make it show the VMHost instead of the "HostSystem-ha-host"?

Like:

Name           Enabled

---------          --------

Server1        True

Tried Get-VMHost | Get-VMHostStartPolicy | select @{Name="Host";Expression={$_.Name}},Enabled but it didn't worked...

Att, Vandrey Trindade
1 Solution

Accepted Solutions
vXav
Expert
Expert
Jump to solution

$_ refers to the previous pipe.

In your case the pipe previous to your $_ was Get-VMHostStartPolicy.

If you do a "Get-VMHostStartPolicy (get-vmhost) | Get-Member" you'll see that there is no "Name" property. The name property of the host is "one pipe before" in Get-VMHost.

get-vmhost | select name,@{L="Enabled";e={($_ | Get-VMHostStartPolicy).enabled}}

View solution in original post

2 Replies
vXav
Expert
Expert
Jump to solution

$_ refers to the previous pipe.

In your case the pipe previous to your $_ was Get-VMHostStartPolicy.

If you do a "Get-VMHostStartPolicy (get-vmhost) | Get-Member" you'll see that there is no "Name" property. The name property of the host is "one pipe before" in Get-VMHost.

get-vmhost | select name,@{L="Enabled";e={($_ | Get-VMHostStartPolicy).enabled}}

vandreytrindade
Enthusiast
Enthusiast
Jump to solution

Thanks!

Att, Vandrey Trindade
0 Kudos