How can I get all VMs that are NOT under a certain grandparent folder ?
You could do something like this
$folderName = 'MyFolder'
Get-VM | where {
(Get-View -ID (Get-View $_.ExtensionData.Parent | Select -ExpandProperty Parent) |
Select -ExpandProperty Name) -ne $folderName}
Or you could use the BlueFolderPath New-VIProperty from my Folder by Path post.
Then it would become
$folderName = 'MyFolder'
Get-VM | where {$_.BlueFolderPath -notmatch $folderName}
If you have multiple folders with the same name, then you can provide the full folderpath, which would be more foolproof in any case.
$folderName = 'DC1/Blue1/MyFolder'
Get-VM | where {$_.BlueFolderPath -notmatch $folderName}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
$folderName = 'MyFolder'
Get-VM | where {
(Get-View -ID (Get-View $_.ExtensionData.Parent | Select -ExpandProperty Parent) |
Select -ExpandProperty Name) -ne $folderName}
Or you could use the BlueFolderPath New-VIProperty from my Folder by Path post.
Then it would become
$folderName = 'MyFolder'
Get-VM | where {$_.BlueFolderPath -notmatch $folderName}
If you have multiple folders with the same name, then you can provide the full folderpath, which would be more foolproof in any case.
$folderName = 'DC1/Blue1/MyFolder'
Get-VM | where {$_.BlueFolderPath -notmatch $folderName}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok thanks!