VMware Cloud Community
StolcP
Contributor
Contributor

VM List with Folders/subfolders

Hello everybody,

 

after long and exhausting searching of a solution to export list of all VMs with full path (Folder+subfolder+another subfolder etc.) I would like to ask you for the solution.

 

I am not the best in PowerCLI but I know how it works and how to use it. I have found only the script to export folders and subfolders but without VMs. It is a datacenter of let's say 500 VMs. 

If it's easy to put inside a solution how to export not only the path but also for example Used space or another information, I would be glad to have it explained by some very easy way. 

Thanks in advance.

0 Kudos
1 Reply
StolcP
Contributor
Contributor

$report = @()
Get-VM | Get-View | %{
$row = "" | select Path, Name, PowerState, DiskUsed
$row.Name = $_.Name
$current = Get-View $_.Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
$row.Path = $path
$report += $row
}
$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

 

 

Okay actually I have this solution to find Path + Name of VM.

Can somebody help me to insert for example PowerState to the prepared row? I will get how to obtain another data and that's it. Thanks! 

0 Kudos