VMware Cloud Community
CG21
Enthusiast
Enthusiast
Jump to solution

get vm with multiple criteria

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

 

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use the RegEx or ('|')

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You could use the RegEx or ('|')

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
CG21
Enthusiast
Enthusiast
Jump to solution

that's ok

thank you

0 Kudos