VMware Cloud Community
homerjnick
Enthusiast
Enthusiast
Jump to solution

PowerCLI - Get-View @Filter with multiple criteria?

I have a script that I run after I update our Linked Clones .  The script runs through VM's for a Resource Pool and creates three scheduled tasks that shutdown, then power off then power on VM's.

Part of my code I have is this:

Get-View -ViewType VirtualMachine -Filter @{"ResourcePool" = "MYRESOURCEPOOL"}

And from I create the scheduled tasks in a For statement.

Instead of creating different scripts or rerunning the thing for other Resource Pools I would prefer to filter the view but refer to multiple Resource Pools.

So something like:

Get-View -ViewType VirtualMachine -Filter @{"ResourcePool" = "MYRESOURCEPOOL1", "MYRESOURCEPOOL2"}



But I can't seem to get the right syntax to filter on multiple resource pools.

Can anyone assist?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The right hand is a RegEx expression, so you can use the RegEx 'or', like this

Get-View -ViewType VirtualMachine -Filter @{"ResourcePool" = "MYRESOURCEPOOL1|MYRESOURCEPOOL2"}


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

The right hand is a RegEx expression, so you can use the RegEx 'or', like this

Get-View -ViewType VirtualMachine -Filter @{"ResourcePool" = "MYRESOURCEPOOL1|MYRESOURCEPOOL2"}


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

homerjnick
Enthusiast
Enthusiast
Jump to solution

Worked a treat, many thanks.

0 Kudos