VMware Cloud Community
vernon_wells
Contributor
Contributor
Jump to solution

Listing folders for VM's

I am trying to document the folder structure inside virtual center.   Is there a way to get at this information through powershell?   I got as far as:

$test = get-vm somevmname

$test.extensiondata.parent

Type                                                                                      Value
----                                                                                      -----
Folder                                                                                    group-v1926

Is there anyway to map group-v1926 back to it's description that is displayed in VC?  Also could this be done recursively to find your way back to the top of the structure if you have nested folders?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The Extensiondata.Parent property is a MoRef (Managed Object Reference), which is in fact a pointer to the actual object.

But in PowerCLI 4.x you don't need to use the Extensiondata to get the folder paths anymore.

You can do something like this

$report = @()
foreach($vm in Get-VM){
   
$parent = $vm.Folder
   
$path = $vm.Name
   
while ($parent){
       
$path = $parent.Name + "/" + $path
       
$parent = $parent.Parent
    }
   
$row = "" | Select VM,Path
   
$row.VM = $vm.Name
   
$row.Path = $path
   
$report += $row
}
$report

This will give you the name of the VM and blue folder path.

If you need to have the yellow folder path, you would need a different script.

Let me know if that is needed as well ?


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

The Extensiondata.Parent property is a MoRef (Managed Object Reference), which is in fact a pointer to the actual object.

But in PowerCLI 4.x you don't need to use the Extensiondata to get the folder paths anymore.

You can do something like this

$report = @()
foreach($vm in Get-VM){
   
$parent = $vm.Folder
   
$path = $vm.Name
   
while ($parent){
       
$path = $parent.Name + "/" + $path
       
$parent = $parent.Parent
    }
   
$row = "" | Select VM,Path
   
$row.VM = $vm.Name
   
$row.Path = $path
   
$report += $row
}
$report

This will give you the name of the VM and blue folder path.

If you need to have the yellow folder path, you would need a different script.

Let me know if that is needed as well ?


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

Reply
0 Kudos
vernon_wells
Contributor
Contributor
Jump to solution

Thanks!   Hope your new book is selling out.   My copy is on the way from amazon.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks, I hope you'll like it Smiley Happy


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

Reply
0 Kudos