Automation

 View Only
  • 1.  How to Filter out specific Operating Systems

    Posted Feb 10, 2016 12:39 PM

    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



  • 2.  RE: How to Filter out specific Operating Systems
    Best Answer

    Posted Feb 10, 2016 12:58 PM

    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



  • 3.  RE: How to Filter out specific Operating Systems

    Posted Feb 10, 2016 03:17 PM

    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



  • 4.  RE: How to Filter out specific Operating Systems

    Posted Feb 10, 2016 03:33 PM

    Thanks for the additional input.