Automation

 View Only
  • 1.  get vm with multiple criteria

    Posted Dec 06, 2021 10:19 AM

    Hi,

    i have to extract the vms which have the se in centos and redhat, how can i create this condition, i have a script like this but the "and" is not recognized

     

     

    $VmInfo = Get-VM | where{$_.Guest.State -eq "Running"} | where{($_.Guest.OSFullName -match "centos") or ($_.Guest.OSFullName -match "Red Hat")}  
    $VMS = ($VmInfo).Name 
    $VMS = $VMS | sort

     

     

    can you help about the correct syntax ?

    thank you

     

     



  • 2.  RE: get vm with multiple criteria
    Best Answer

    Posted Dec 06, 2021 10:54 AM

    You could use the RegEx or ('|')

    where{$_.Guest.State -eq "Running" -and $_.Guest.OSFullName -match "centos|Red Hat"}  
    


  • 3.  RE: get vm with multiple criteria

    Posted Dec 06, 2021 12:48 PM

    that's ok

    thank you