Hi guys,
I would like to select all VMs in my environment that DO NOT reside in the INFRA folder. I'm not having much luck doing it on my own, I would imagine it's something like:
get-folder | select -name isnot "INFRA" | get-vm
Maybe I'm way off, I'm not having much luck finding an example close to what I'm trying to achieve on my own. Could anyone give me a hand?
Thanks.
Found it, you have to add the NoRecursion switch
Get-Folder | where{$_.Name -notmatch 'INFRA'} | Get-VM -NoRecursion | Select Name,Folder
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would go for a Wher-clause with a notmatch on a RegEx expression.
Something like this
Get-Folder | where{$_.Name -notmatch 'INFRA'} | Get-VM
And if you want to exclude only INFRA and not for example INFRA1, you could do
Get-Folder | where{$_.Name -notmatch '^INFRA$'} | Get-VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the help LucD!
Spoke too soon, looks like it's still returning VMs from the INFRA folder:
It almost looks like a glitch of some kind because if I use match I only get results in INFRA which I would expect, but notmatch returns everything including INFRA:
Can you try with the exact notmatch option I gave earlier.
Does that make a difference?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Found it, you have to add the NoRecursion switch
Get-Folder | where{$_.Name -notmatch 'INFRA'} | Get-VM -NoRecursion | Select Name,Folder
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That got it, thanks again LucD!