Hi All,
I am looking for a script to get the total ESXi count from multiple VCs , requirements are as follows
1. Input file with all the VC names
2. Script should find the total ESXi count per VC and redirect the output to a csv file (two columns 1. VC name 2. Total ESXi count)
I tried and found few scripts but all the scripts calls Get-Cluster and then host count per cluster, I couldn't find any script calls Get-VMhost.count directly and find the count. Can any one help me with this ?
I want to schedule the script so that it can run on daily basis and store the output file on a given location.
You have to use the Server parameter to restrict the output to one specific vCenter.
$report = Foreach($vc in $global:DefaultVIServers){
New-Object -TypeName PSObject -Property @{
vCenter = $vc.Name
HostCount = (Get-VMHost -Server $vc).count
}
}
$report | Export-Csv C:\Users\hlp_muthusur1\vClusterListInfo.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you call Get-VMHost with the Server parameter it should give you the count of ESXi nodes per vCenter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-VMHost with server parameters list out all the hosts with other informations like connection state , memory usage etc ..
(Get-VMHost).count -- this gives the host count which I am looking for. just the total count in numeric value.
Basically, I modified the following script to get the output in csv with colums VC name and host count. but it didnt work
Found this script posted by you LucD it works very well as it is . But I am struggling to make it to work to get the desired format which I am looking for
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
Modified one that didnt work:
Sorry , I am very new to powercli. following script may have many mistakes...
Connect-viserver -Server (Get-Content C:\Users\hlp_muthusur1\vCList_test.txt) > $null
$report = Foreach($vc in $global:DefaultVIServers){
$hostcount = (Get-VMHost).count;
}
$report | Export-Csv C:\Users\hlp_muthusur1\vClusterListInfo.csv
You have to use the Server parameter to restrict the output to one specific vCenter.
$report = Foreach($vc in $global:DefaultVIServers){
New-Object -TypeName PSObject -Property @{
vCenter = $vc.Name
HostCount = (Get-VMHost -Server $vc).count
}
}
$report | Export-Csv C:\Users\hlp_muthusur1\vClusterListInfo.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much. It worked.