VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

get-vm with windows and powered on

Hi,

Please help to get the list of all windows VMs that powered on

I am stuck with this how can i add another parameter

get-vm | Where {$_.Guest -match 'windows'}

Please help

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Or use the more accurate and faster

(Get-VM).where{$_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows'}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

11 Replies
SupreetK
Commander
Commander
Jump to solution

You can use the below command -

Get-VM | ? {($_.GuestId -match "Windows") -and ($_.powerstate -eq "PoweredOn")}

Please consider marking this answer as "correct" or "helpful" if you think your questions have been answered.

Cheers,

Supreet

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Or use the more accurate and faster

(Get-VM).where{$_.PowerState -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows'}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SupreetK
Commander
Commander
Jump to solution

LucD​ - Can you please explain how your command would be more accurate and faster than the one I shared? Since I have just started to learn PowerShell (and PowerCLI), your inputs will definitely help me understand more Smiley Happy

Cheers,

Supreet

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure.

The where method, as I also showed in my recent VMworld session, is faster than the Where-Object cmdlet.

The test on the Guest property is comparing the string representation of the complete Guest object, while the actual OS name is in the nested property $_.Guest.OSFullName.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SupreetK
Commander
Commander
Jump to solution

Oh nice! When we run <Get-VM -Name VM_Name | Format-List *>, we do not see the property 'Guest.OSFullName'. How do we obtain a list of available nested properties?

Cheers,

Supreet

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Use the Format-Custom cmdlet with the Depth parameter.

For example (but be aware that this produces a lot of output)

Get-VM -Name MyVM |

Format-Custom -Depth 2

PS: and please stop begging for points in your replies. That is not considered good practice.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SupreetK
Commander
Commander
Jump to solution

Custom indeed produces a lot of output Smiley Happy Thanks, again!

Regarding the points, I don't mention it for all the replies. Anyways, will have none going forward Smiley Happy

Cheers,

Supreet

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

thumbs.jpg


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
srik12
Contributor
Contributor
Jump to solution

How to get the powered on vm's list with vmtools and tools version.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VM | where{$_.PowerState -eq 'PoweredOn'} |

Select Name,PowerState,@{N='ToolsVersion';E={$_.Guest.ToolsVersion}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

srik12
Contributor
Contributor
Jump to solution

Thank you, i am able to pull the list.

i have used the below one.

Get-VM | where{$_.PowerState -eq 'PoweredOn'} | Select Name,PowerState,@{N=”HardwareVersion”; E={$_.Extensiondata.Config.Version}}, @{N=”ToolsVersion”; E={$_.Extensiondata.Config.Tools.ToolsVersion}},@{N=”ToolsStatus”; E={$_.Extensiondata.Summary.Guest.ToolsStatus}},@{N=”ToolsVersionStatus”; E={$_.Extensiondata.Summary.Guest.ToolsVersionStatus}}, @{N=”ToolsRunningStatus”; E={$_.Extensiondata.Summary.Guest.ToolsRunningStatus}}

Reply
0 Kudos