VMware Cloud Community
AGFlora
Enthusiast
Enthusiast
Jump to solution

Get a list of Remaining XP VMs

Hi

For some reason the Guest OS column is coming back blank.

@{N='Guest OS;E={$_.guest.OSfullname) | Where-Object {$_.Name -like "XP*"}}}

What am I dong wrong?

Thanks

0 Kudos
1 Solution

Accepted Solutions
MKguy
Virtuoso
Virtuoso
Jump to solution

Use a statement like this:

Get-VM | Select Name, @{N="Guest OS"; E={$_.Guest.OSFullname}} | Where-Object { $_."Guest OS" -like "*XP*" }

-- http://alpacapowered.wordpress.com

View solution in original post

0 Kudos
10 Replies
MKguy
Virtuoso
Virtuoso
Jump to solution

Use a statement like this:

Get-VM | Select Name, @{N="Guest OS"; E={$_.Guest.OSFullname}} | Where-Object { $_."Guest OS" -like "*XP*" }

-- http://alpacapowered.wordpress.com
0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

That worked. Thanks!

0 Kudos
MKguy
Virtuoso
Virtuoso
Jump to solution

Just one thing to point out:

The above will query the OS that is detected by the VMware Tools running inside the Guest OS. If you don't have the VMware Tools installed, it will not detect any OS.

The static guest OS you configure in the VM settings or when creating a VM uses another parameter (ExtensionData.Config.GuestId), which you can combine in a query like this:

Get-VM | Select Name, @{N="Guest OS"; E={$_.Guest.OSFullname}}, @{N="ConfigOS"; E={$_.ExtensionData.Config.GuestId}} | Where-Object { ($_."Guest OS" -like "*XP*") -or ($_.ConfigOS -like "*XP*")}


Because that configuration parameter is static but you can still install other OSes, you may see mismatches between what the detected guest OS and what the VM is actually configured for.

-- http://alpacapowered.wordpress.com
AGFlora
Enthusiast
Enthusiast
Jump to solution

Very useful information....Thanks again!

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

I'm having a little trouble when trying to put it all together:

Get-VM | select  @{N="VM"; E={$_.Name}}, 

                                       @{N="GuestOS"; E={$_.Guest.OSFullname}}, @{N="ConfigOS"; E={$_.ExtensionData.Config.GuestId}} |

                                       Where-Object { ($_."GuestOS" -like "*XP*") -or ($_.ConfigOS -like "*XP*")},

                                       @{N="PowerState"; E={$_.PowerState}},

                                       @{N="ToolsStaus"; E={$_.extensiondata.guest.toolsversionstatus}}

Error:

@{N="ConfigOS"; E={$_.ExtensionData.Config.GuestId}} | Where-Object <<<<  {

_."GuestOS" -like "*XP*") -or ($_.ConfigOS -like "*XP*")},

  + CategoryInfo          : InvalidArgument: (:) [Where-Object], ParameterBi

ndingException

  + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Comma

nds.WhereObjectCommand

0 Kudos
MKguy
Virtuoso
Virtuoso
Jump to solution

The Where-Object filter needs to be placed at the end, after you enumerate all the fields, i.e.:

Get-VM | Select  @{N="VM"; E={$_.Name}}, 

                                       @{N="GuestOS"; E={$_.Guest.OSFullname}},

                                       @{N="ConfigOS"; E={$_.ExtensionData.Config.GuestId}},

                                       @{N="PowerState"; E={$_.PowerState}},

                                       @{N="ToolsStatus"; E={$_.extensiondata.guest.toolsversionstatus}} | Where-Object { ($_.GuestOS -like "*XP*") -or ($_.ConfigOS -like "*XP*")}

-- http://alpacapowered.wordpress.com
AGFlora
Enthusiast
Enthusiast
Jump to solution

Ah...I did move some of the objects above the Where-Object filter earlier but didn't think to put the filter at the very end...Thanks again!

0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

This code is working pretty good with the exception that for some reason it's listing all OS versions instead of just XP when I run it against certain datacenters

0 Kudos
MKguy
Virtuoso
Virtuoso
Jump to solution

The Where filter as implemented in my example is deterministic on the string-level, it shouldn't output anything that doesn't match it.

Please post the full code you're using and an excerpt from the output.

-- http://alpacapowered.wordpress.com
0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

The script is working as desired now. The mistake was on my part. Thanks for your help.

0 Kudos