VMware Cloud Community
SureshKumarMuth
Commander
Commander
Jump to solution

Power cli script to get the ESXi count per vCenter server

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.

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You have to use the Server parameter to restrict the output to one specific vCenter.

Connect-viserver -Server (Get-Content C:\Users\hlp_muthusur1\vCList_test.txt) > $null

$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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander
Jump to solution

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 LucDSmiley Happy 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

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You have to use the Server parameter to restrict the output to one specific vCenter.

Connect-viserver -Server (Get-Content C:\Users\hlp_muthusur1\vCList_test.txt) > $null

$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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander
Jump to solution

Thank you very much. It worked.

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos