Got this far
Get-VMHost | Select @{N="Datacenter";E={datacenter -VMHost $_}}, Name, @{N="NumVM";E={($_ | Get-VM).Count}} | Sort datacenter, NumVM
but not able to get it to dump the top level folder.
I have VC, Folders, Datacenters, hosts then VM's
Thanks
Ok, got it.
Try like this
Get-VMHost |
Select @{N="Datacenter";E={Get-Datacenter -VMHost $_}},
Name,
@{N="NumVM";E={($_ | Get-VM).Count}},
@{N='Folder';E={
$location = Get-View -Id $_.ExtensionData.Parent
$folder = ''
do{
if($location -is [VMware.Vim.Folder] -and $location.Name -ne 'host'){
$folder = $location
}
$location = Get-View -Id $location.Parent
}
until($location.Name -eq 'Datacenters')
$folder.Name
}} |
Sort datacenter, NumVM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-VMHost |
Select @{N="Datacenter";E={Get-Datacenter -VMHost $_}},
Name,
@{N="NumVM";E={($_ | Get-VM).Count}},
@{N='Folder';E={
$location = Get-View -Id $_.ExtensionData.Parent
$names = @()
do{
if($location -is [VMware.Vim.Folder] -and $location.Name -ne 'host'){
$names += $location.Name
}
$location = Get-View -Id $location.Parent
}
until(-not $location.Parent)
$names[-1]
}} |
Sort datacenter, NumVM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This did not work it returned nothing.
It works for me.
Do you actually have a layout Folder - Datacenter - Cluster - VMHost?
If not, it will indeed return nothing for the Folder property.
Perhaps provide a screenshot of the layout?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No cluster just folder, datacenter,host then VM's some vm's are behind resource_pools. In some cases there are clusters
Here is the output from your code no out put for folder
Datacenter Name NumVM Folder
---------- ---- ----- ------
GLO nyesx67.englab.juniper.net 77
GLO nyinfra01.englab.juniper.net 8
GLO nyinfra02.englab.juniper.net 5
fwlab-pdt pdtbl-esx03.englab.junipe... 13
fwlab-pdt pdtbl-esx02.englab.junipe... 22
fwlab-pdt nyesx07.spglab.juniper.net 55
fwlab-perf nyesx39.spglab.juniper.net 4
fwlab vsrxdevesx01.spglab.junip... 99
fwlab vsrxdevesx02.spglab.junip... 60
fwlab vsrxdevesx04.spglab.junip... 14
fwlab vsrxdevesx08.spglab.junip... 22
fwlab srx-forge-08.spglab.junip... 2
Ok, got it.
Try like this
Get-VMHost |
Select @{N="Datacenter";E={Get-Datacenter -VMHost $_}},
Name,
@{N="NumVM";E={($_ | Get-VM).Count}},
@{N='Folder';E={
$location = Get-View -Id $_.ExtensionData.Parent
$folder = ''
do{
if($location -is [VMware.Vim.Folder] -and $location.Name -ne 'host'){
$folder = $location
}
$location = Get-View -Id $location.Parent
}
until($location.Name -eq 'Datacenters')
$folder.Name
}} |
Sort datacenter, NumVM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yup that did it thanks