Hi,
I'm looking to query a list of vCenters (pulled from a text file) for the following information, and then output to a csv file.
I have tried modifying LucD's script documented in the below article, but with no luck.
Powercli script to get datacenter and it's clusters, hosts ands vm's in a CSV file. unknown
Try like this
Foreach($vc in $global:DefaultVIServers){
foreach($dc in Get-Datacenter -Server $vc){
Get-Cluster -Location $dc -Server $vc |
Select @{N='VC';E={$vc.Name}},
@{N='Datacenter';E={$dc.Name}},
@{N='Cluster';E={$_.Name}},
@{N='#ESXi';E={$_.ExtensionData.Host.Count}},
@{N='#VM';E={(Get-View -Id $_.ExtensionData.Host).Vm.Count}}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The table column headers are:
| vCenter Name | Datacenter Name | Cluster Name | No. of Cluster Hosts | No. of Cluster VMs |
Try like this
Foreach($vc in $global:DefaultVIServers){
foreach($dc in Get-Datacenter -Server $vc){
Get-Cluster -Location $dc -Server $vc |
Select @{N='VC';E={$vc.Name}},
@{N='Datacenter';E={$dc.Name}},
@{N='Cluster';E={$_.Name}},
@{N='#ESXi';E={$_.ExtensionData.Host.Count}},
@{N='#VM';E={(Get-View -Id $_.ExtensionData.Host).Vm.Count}}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc, it works a treat!
I added a few mods (that Luc has previously shown me in previous threads) that perhaps others may be interested in:
Connect-viserver -Server (Get-Content C:\Scripts\vCList_test.txt) > $null
$report = Foreach($vc in $global:DefaultVIServers){
foreach($dc in Get-Datacenter -Server $vc){
Get-Cluster -Location $dc -Server $vc |
Select @{N='VC';E={$vc.Name}},
@{N='Datacenter';E={$dc.Name}},
@{N='Cluster';E={$_.Name}},
@{N='#ESXi';E={$_.ExtensionData.Host.Count}},
@{N='#VM';E={(Get-View -Id $_.ExtensionData.Host).Vm.Count}}
}
}
$report | Export-Csv C:\Scripts\vClusterListInfo.csv
how can we add expresion that will add virtual hardware versions to these VMs also?
Thanks
Not sure I understand the question, the script will have an entry per cluster, not per VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
thanks for reply
what I was looking for is script that will output virtual machines name, virtual hardware version, host name,cluster name and vcenter where vms running in csv format
sorry for not properly formulated question
Thanks