Hi All,
I have the following, working, script that outputs VM names and the full folder hierarchy they're in. I need to add detail for vCPU count and Memory. Can you help?
$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
Thanks,
DS
Try like this, I optimised the script a bit for speed.
$report = @()
Get-View -ViewType VirtualMachine -Property Name,Parent,Config.Hardware | %{
$row = "" | select Name, Path, vCPU, MemoryMB
$row.Name = $_.Name
$current = Get-View $_.Parent -Property Name,Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent -Property Name,Parent
} while ($current.Parent -ne $null)
$row.Path = $path
$row.vCPU = $_.Config.Hardware.NumCPU
$row.MemoryMB = $_.Config.Hardware.MemoryMB
$report += $row
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this, I optimised the script a bit for speed.
$report = @()
Get-View -ViewType VirtualMachine -Property Name,Parent,Config.Hardware | %{
$row = "" | select Name, Path, vCPU, MemoryMB
$row.Name = $_.Name
$current = Get-View $_.Parent -Property Name,Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent -Property Name,Parent
} while ($current.Parent -ne $null)
$row.Path = $path
$row.vCPU = $_.Config.Hardware.NumCPU
$row.MemoryMB = $_.Config.Hardware.MemoryMB
$report += $row
}
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This could not have worked better. Thank you for the help, and Happy Holidays!