VMware Cloud Community
underlineX
Contributor
Contributor

PowerShell to show all windows devices in vSphere

I have been using PowerShell in vSphere for a short couple months. Using my Win10 machine I run PowerShell script: 

Connect-VIServer [domain name of vSphere]

Then I use the script, which list out all the Windows Servers and Linux: 
Get-vm | Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}}

 

 

 

Labels (1)
Tags (2)
Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership

Is there a question in here?


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

Reply
0 Kudos
underlineX
Contributor
Contributor

@LucD Yes, Thanks: There was intended to be a question written in that post. Must have been multi tasking.
The question is could I get assistance providing the correct way to query in PowerShell all windows servers while I am logging into vSphere?

Reply
0 Kudos
LucD
Leadership
Leadership

Still not sure what the actual question is.
Do you want to list all VMs that have a Windows Guest OS running?
Do you have VMware Tools installed on all your VMs?


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

Reply
0 Kudos
underlineX
Contributor
Contributor

@LucD Yes, I have VM tools installed.
Yes, I would to list out all VMs that have Windows Guest OS Running along with their powered state. Additionally, I was curious to know if I can just flip the verbiage in the same command and list out all the Linux machines. 

Long term, I am wanting to Log into vSphere and find out what systems are running: (servers or desktops) and run weekly updates.

Thanks 

Reply
0 Kudos
LucD
Leadership
Leadership

You can list the Guest OS with

Get-VM |
Select Name,
    @{N=“OS“;E={$_.ExtensionData.Summary.Config.GuestFullName}}

To filter for Windows or Linux, you could do one of the following

Get-VM |
where{$_.ExtensionData.Summary.Config.GuestFullName -like "*Windows*"} |
Select Name

or

Get-VM |
where{$_.ExtensionData.Summary.Config.GuestFullName -like "*Linux*"} |
Select Name


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

underlineX
Contributor
Contributor

@LucD Thank-You for script assistance. 

I attempted to recreate the script to answer my needs of outputting: VMName, VMHost(IP), PowerState, GuestOS/runningOS) from my vSphere environment. The script works with no errors.

However it fails on two points, "It did not filter for Windows or Linux" and "It did not provide the Guest OS name; Windows Server or Ubuntu" It shows False/True ----

Why??? What did I Miss ???

Get-VM | Select @{Label = "VM Name" ; Expression = {$_.Name} },VMHost, PowerState, @{Label = "Guest OS" ; Expression = {$_.ExtensionData.Summary.Config.GuestFullName -like "*Windows*"} }|
Export-CSV -Path 'C:\users\username\documents\VMPowerOS.csv' -NoTypeInformation

Reply
0 Kudos
LucD
Leadership
Leadership

The Expression for that calculated property (Guest OS) will result in $true or $false, not the name of the Guest OS.
Move the Where-clause

Get-VM |
Where-Object { $_.ExtensionData.Summary.Config.GuestFullName -like "*Windows*" } |
Select @{Label = "VM Name" ; Expression = {$_.Name} },
    VMHost, PowerState, 
    @{Label = "Guest OS" ; Expression = {$_.ExtensionData.Summary.Config.GuestFullName} }|
Export-CSV -Path 'C:\users\username\documents\VMPowerOS.csv' -NoTypeInformation

  


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

underlineX
Contributor
Contributor

@LucD Thank-You that worked

Reply
0 Kudos