PowerCLI

 View Only
Expand all | Collapse all

get-vm with windows and powered on

  • 1.  get-vm with windows and powered on

    Posted Aug 31, 2018 01:01 PM

    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



  • 2.  RE: get-vm with windows and powered on

    Posted Aug 31, 2018 06:17 PM

    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



  • 3.  RE: get-vm with windows and powered on
    Best Answer

    Posted Sep 02, 2018 05:31 AM

    Or use the more accurate and faster

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



  • 4.  RE: get-vm with windows and powered on

    Posted Sep 02, 2018 08:31 AM

    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 :smileyhappy:

    Cheers,

    Supreet



  • 5.  RE: get-vm with windows and powered on

    Posted Sep 02, 2018 10:42 AM

    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.



  • 6.  RE: get-vm with windows and powered on

    Posted Sep 02, 2018 11:10 AM

    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



  • 7.  RE: get-vm with windows and powered on

    Posted Sep 02, 2018 11:18 AM

    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.



  • 8.  RE: get-vm with windows and powered on

    Posted Sep 02, 2018 12:06 PM

    Custom indeed produces a lot of output :smileyhappy: Thanks, again!

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

    Cheers,

    Supreet



  • 9.  RE: get-vm with windows and powered on

    Posted Sep 02, 2018 12:09 PM



  • 10.  RE: get-vm with windows and powered on

    Posted Jan 29, 2020 08:05 AM

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



  • 11.  RE: get-vm with windows and powered on

    Posted Jan 29, 2020 08:23 AM

    Try something like this

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

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



  • 12.  RE: get-vm with windows and powered on

    Posted Jan 30, 2020 09:59 AM

    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}}