Automation

 View Only
  • 1.  get all powered on vms windows type

    Posted Feb 13, 2018 09:21 PM

    hi

    any idea why this is not working?

    get-vm | ? {$_.powerstate -eq "PoweredOn" -and {$_.extensiondata.guest.guestfullname -match "Microsoft*"}}

    its showing linux as well



  • 2.  RE: get all powered on vms windows type
    Best Answer

    Posted Feb 13, 2018 09:24 PM

    That shouldn't be curly braces.

    Try like this

    Oh, and -match expects a RegEx, so do not use the asterisks, unless you really want it there.

    In a RegEx it doesn't mean the same thing as for a -like

    get-vm | ? {($_.powerstate -eq "PoweredOn") -and ($_.extensiondata.guest.guestfullname -match "Microsoft")}



  • 3.  RE: get all powered on vms windows type

    Posted Feb 13, 2018 09:37 PM

    LucD You're like my much wiser clone I love it. :smileyhappy: Much to learn from you so take it easy on me :smileywink:



  • 4.  RE: get all powered on vms windows type

    Posted Feb 13, 2018 09:50 PM

    Thank you both!



  • 5.  RE: get all powered on vms windows type

    Posted Feb 13, 2018 10:01 PM

    is there a better or shorter query to run for this

    get-vm | ? {($_.powerstate -eq "PoweredOn") -and ($_.extensiondata.guest.guestfullname -match "Microsoft")} | select NAme, @{N="tools";e={$_.extensiondata.guest.toolsstatus}}, @{N="vmhardware";e={$_.extensiondata.config.version}} | sort vmhardware | ft -AutoSize



  • 6.  RE: get all powered on vms windows type

    Posted Feb 14, 2018 05:39 AM

    Not shorter, but definitely faster

    Get-View -ViewType VirtualMachine -Property Name,Runtime.PowerState,Guest,Config.Version -Filter @{'Runtime.PowerState'='poweredOn'} |

    where{$_.Guest.GuestFullName -match 'Windows'} |

    select Name, @{N="Tools";e={$_.guest.toolsstatus}},

        @{N="vmhardware";e={$_.config.version}} |

    Sort-Object -Property vmhardware |

    ft -AutoSize



  • 7.  RE: get all powered on vms windows type

    Posted Feb 13, 2018 09:28 PM

    This should work for you.

    get-vm | where {$_.powerstate -eq "PoweredOn" -and $_.extensiondata.guest.guestfullname -like 'Microsoft*'