VMware Cloud Community
466kdl1
Enthusiast
Enthusiast
Jump to solution

Need script for to get cluster name, esxi host name and VM's count in the cluster and last core and sockets. for licensing

Hey Guys can you help my required . I was able to get the  details esxi host  cores and socket  but  cluster name and Vm's count

Need script for to get  cluster name, esxi host name and VM's count in the cluster and last core and sockets. for licensing

Here is the script am using.

$result = @()

$vmhost = get-vmhost

foreach ($esxi in $vmhost) {

   

    $HostCPU = $esxi.ExtensionData.Summary.Hardware.NumCpuPkgs

    $HostCPUcore = $esxi.ExtensionData.Summary.Hardware.NumCpuCores/$HostCPU

    $obj = new-object psobject

    $obj | Add-Member -MemberType NoteProperty -Name name -Value $esxi.Name

    $obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $HostCPU

    $obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $HostCPUcore

    $result += $obj

}

$result | Export-Csv esxireport.csv -NoTypeInformation -UseCulture

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You forgot a comma at the end of the previous line.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
19 Replies
scott28tt
VMware Employee
VMware Employee
Jump to solution

Moderator: Moved to PowerCLI


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-Cluster -PipelineVariable cluster | Get-VMHost |

Select @{N='Cluster';E={$cluster.Name}}, Name,

    @{N='VMonCluster';E={(Get-VM -Location $cluster).Count}},

    @{N='VMonEsx';E={(Get-VM -Location $_).Count}},

    @{N='CPUSocket';E={$_.ExtensionData.Summary.Hardware.NumCpuPkgs}},

    @{N='Corepersocket';E={$_.ExtensionData.Summary.Hardware.NumCpuCores/$_.ExtensionData.Summary.Hardware.NumCpuPkgs}} |

Export-Csv esxireport.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

harrytoole
Enthusiast
Enthusiast
Jump to solution

There is a kb article on it for just this such thing:

KB77098

VMware Knowledge Base

0 Kudos
466kdl1
Enthusiast
Enthusiast
Jump to solution

Awesome and very quick response.

0 Kudos
466kdl1
Enthusiast
Enthusiast
Jump to solution

Hey Lucd,

Am trying to get OS version and counts of windows VM's in the environment. So just added it  like below. but getting errors.

Get-Cluster -PipelineVariable cluster | Get-VMHost |

Select @{N='Cluster';E={$cluster.Name}}, Name,

    @{N='VMonCluster';E={(Get-VM -Location $cluster).Count}},

    @{N='VMonEsx';E={(Get-VM -Location $_).Count}},

    @{N='CPUSocket';E={$_.ExtensionData.Summary.Hardware.NumCpuPkgs}},

    @{N='Corepersocket';E={$_.ExtensionData.Summary.Hardware.NumCpuCores/$_.ExtensionData.Summary.Hardware.NumCpuPkgs}}

    @{N='WinVM';E={(Get-VM -Location $_ | where{$_.Guest.OSFullName -match "Windows"}).Count}} |

    Export-Csv esxireport.csv -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which errors are you getting?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
466kdl1
Enthusiast
Enthusiast
Jump to solution

Errors :

pastedImage_0.png

AM expecting output is :

Cluster Name ||VMonCluster || VMonEsx || CPUSocket || Corepersocket ||Win VM's count each host || OSversion

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You forgot a comma at the end of the previous line.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
466kdl1
Enthusiast
Enthusiast
Jump to solution

Yes  got it .

and also am looking OS version.if we can add this(@{N='WinVM';E={(Get-VM -Location $_ | where{$_.Guest.OSFullName ) will works to get the OS version ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not really, the lowest loop is over ESXi nodes.

You can get the OS name of each VM on that ESXi node, but it could potentially be a long list.

Something like this

Get-Cluster -PipelineVariable cluster | Get-VMHost |

Select @{N='Cluster';E={$cluster.Name}}, Name,

    @{N='VMonCluster';E={(Get-VM -Location $cluster).Count}},

    @{N='VMonEsx';E={(Get-VM -Location $_).Count}},

    @{N='CPUSocket';E={$_.ExtensionData.Summary.Hardware.NumCpuPkgs}},

    @{N='Corepersocket';E={$_.ExtensionData.Summary.Hardware.NumCpuCores/$_.ExtensionData.Summary.Hardware.NumCpuPkgs}},

    @{N='WinVM';E={(Get-VM -Location $_ | where{$_.Guest.OSFullName -match "Windows"}).Count}},

    @{N='WinVMOS';E={(Get-VM -Location $_ | where{$_.Guest.OSFullName -match "Windows"}).OSFullName -join '|'}} |

Export-Csv esxireport.csv -NoTypeInformation -UseCulture

Or do you mean something else?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
stevegott63
Contributor
Contributor
Jump to solution

This works great on my 6.7 stuff but seems to be failing on my 7.0 stuff. Are there any changes to POWERCLI that might need to happen?

0 Kudos
stevegott63
Contributor
Contributor
Jump to solution

To clarify the script runs without error in both environments but does not return CPU Sockets or CoresPerSocket on my 7.0 environment.

Tags (1)
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just tested with PowerCLI 13.0 in vSphere 7.0.3, and the values for CPU sockets and CoresPerSocket seem to be correct for me.

Which PowerShell and PowerCLI versions are you using?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
stevegott63
Contributor
Contributor
Jump to solution

I am on Power CLI 12.0 . Powershell information is as follows:

PS C:\Users\gotts> $PSVersionTable

Name                                      Value
----                                           -----
PSVersion                                5.1.19041.1320
PSEdition Desktop
PSCompatibleVersions            {1.0, 2.0, 3.0, 4.0...}
BuildVersion                             10.0.19041.1320
CLRVersion                              4.0.30319.42000
WSManStackVersion               3.0
PSRemotingProtocolVersion   2.3
SerializationVersion                  1.1.0.1

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is not the latest PowerCLI release, but that shouldn't cause those issues you are seeing.

What incorrect numbers do you actually see?
Are the values in the Web GUI you see for the ESXi nodes different from what the script is reporting?
Can you share an example?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
stevegott63
Contributor
Contributor
Jump to solution

I tried to upgrade PowerCLI to 13.0 but I don't think it was accomplished correctly, please advise if this is normal?

PS C:\WINDOWS\system32> get-module -ListAvailable "VMware.PowerCLI" | select version

Version
-------
12.0.0.15947286
13.0.0.20829139
12.2.0.17538434
13.0.0.20829139

Tags (1)
0 Kudos
stevegott63
Contributor
Contributor
Jump to solution

I get null values, those columns are empty, for CPU Sockets and Cores on the hosts that are running 7.0 u3.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The multiple PowerCLI versions you seem to have might be the cause of the issues.

The best is to remove them all.
Check where they are located with

Get-Module -Name VMware.PowerCLI -ListAvailable

That should give you all the folders where a PowerCLI version is installed.
Then remove all the PowerCLI related folders in each of these locations.
You can do this from the File Explorer, provided none of these modules is in use (close all PS and PowerCLI sessions).

Finally, do a new Install-Module.




Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
stevegott63
Contributor
Contributor
Jump to solution

Thanks for the information, cleaning up my Powercli versions fixed my issue.

Blessings on you this season!

0 Kudos