Hi everyone -
I'm trying to run "get-vm -tag" and filter by using multiple tags.
So for example, let's say I'm connected to 2 vCenters with powercli. We have 2 categories with different tags. Let's say 1 category is "application" (tags A1, A2...) and the other is "team ownership" (tags TO1, TO2, ...)
I'm trying to run:
get-vm -tag A1 | get-vm -tag TO1
to identify the application #1 and then filter on the team owner #1. So instead of getting 30 servers tagged with app #1, I get the 5 servers within the app #1 that team #1 owns.
Obviously I'm doing something wrong! 🙂
Any suggestions on how to do this?
Thanks-
Dan
The best I could come up with is something like this
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc!! That worked for me. I'm able to filter now.
Best regards-
Dan
If you have to do this with many tags, this is one way:
$taglist = "TAG-1", "TAG-2", "TAG-3"
Get-VM | ForEach-Object {
$tags = (Get-TagAssignment -Entity $_).Tag.Name
if(($taglist | ForEach-Object {$tags -contains $_}) -notcontains $false) {$_}
}