VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Selecting VMs based on grandparent folder

How can I get all VMs that are NOT under a certain grandparent folder ?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

ok thanks!

0 Kudos