This script reports all VMs and the path to the "blue" folder they are in
$report = @() Get-VM | Get-View | %{ $row = "" | select Name, Path $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
The script can easily be converted to a filter, this will allow you to find the folder path for one or more specific VMs.
The filter looks like this
filter Get-FolderPath { $_ | Get-View | % { $row = "" | select Name, Path $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 $row } }
With the filter you can now use it like this
Get-VM PC* | Get-FolderPath
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script reports all VMs and the path to the "blue" folder they are in
$report = @() Get-VM | Get-View | %{ $row = "" | select Name, Path $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
The script can easily be converted to a filter, this will allow you to find the folder path for one or more specific VMs.
The filter looks like this
filter Get-FolderPath { $_ | Get-View | % { $row = "" | select Name, Path $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 $row } }
With the filter you can now use it like this
Get-VM PC* | Get-FolderPath
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Working good!
Thanks again!