Hi,
I'm trying to filter out specific Operating systems. This is what I have so far but it's not working:
New-VIProperty -Name ToolsStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsStatus' -Force
New-VIProperty -Name GuestOS -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.GuestFullName' -Force
Get-VM | Where-Object {$_.Config.GuestFullName -Notlike "Microsoft Windows Server*" -or $_.Name.Config.GuestFullName -Notlike "Linux*"} |
Select Name,PowerState,ToolsStatus, GuestOS
I suspect that should be and -and instead of an -or.
I also changed the NotLike to NotMatch, avoids the asterisk, and the text can appear anywhere in the string
Try like this
New-VIProperty -Name ToolsStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsStatus' -Force
New-VIProperty -Name GuestOS -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.GuestFullName' -Force
Get-VM | Where-Object {$_.GuestOS -NotMatch "Microsoft Windows Server" -and $_.GuestOS -NotMatch "Linux"} |
Select Name,PowerState,ToolsStatus, GuestOS
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I suspect that should be and -and instead of an -or.
I also changed the NotLike to NotMatch, avoids the asterisk, and the text can appear anywhere in the string
Try like this
New-VIProperty -Name ToolsStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsStatus' -Force
New-VIProperty -Name GuestOS -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.GuestFullName' -Force
Get-VM | Where-Object {$_.GuestOS -NotMatch "Microsoft Windows Server" -and $_.GuestOS -NotMatch "Linux"} |
Select Name,PowerState,ToolsStatus, GuestOS
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What Luc said. Just adding to that, you can shorten it to a single (not)match statement by grouping the regex with alternations like this:
Get-VM | Where-Object {$_.GuestOS -NotMatch "(Microsoft Windows Server|Linux)"} |
Select Name,PowerState,ToolsStatus, GuestOS
Thanks for the additional input.
