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
Use a statement like this:
Get-VM | Select Name, @{N="Guest OS"; E={$_.Guest.OSFullname}} | Where-Object { $_."Guest OS" -like "*XP*" }
Use a statement like this:
Get-VM | Select Name, @{N="Guest OS"; E={$_.Guest.OSFullname}} | Where-Object { $_."Guest OS" -like "*XP*" }
That worked. Thanks!
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.
Very useful information....Thanks again!
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
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*")}
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!
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
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.
The script is working as desired now. The mistake was on my part. Thanks for your help.