VMware Cloud Community
Anton_Louw
Contributor
Contributor

Get VM CPU, Sockets and Cores per socket details

Hi Everybody,

We are busy doing an audit in our environment, and I need to pull CPU and CPU Core information on specific VMs in a text document. I have tried, but I cannot seem to get it right.

Does anybody know of a script I can run in powershell to pull this information from the VMs in my text document?

I would appreciate the help.

Thanks

0 Kudos
11 Replies
LucD
Leadership
Leadership

In which language are you writing that script?
What do you already have, and what specifically is not working?


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

0 Kudos
UdayenduKar
Contributor
Contributor

You can use RVTools. Its a lifesaver in such situation.

Download Link: https://www.robware.net/rvtools/download/

Know more using https://www.robware.net/rvtools/  link.

LucD
Leadership
Leadership

Assuming you mean a script in PowerCLI, you could do

Get-VM -Name (Get-Content -Path .\vmnames.txt) |
Select Name,
    @{N='Sockets';E={$_.ExtensionData.Config.Hardware.NumCpu}},
    @{N='CoresPerSocket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

0 Kudos
ZibiM
Enthusiast
Enthusiast

There is a fling for the optimization of the CPU and NUMA settings

It outputs what you are asking for in xls format

https://flings.vmware.com/virtual-machine-compute-optimizer

 

Anton_Louw
Contributor
Contributor

Hi @LucD 

Thanks. Apologies, I was being very vague. You are correct, I am using PowerCLI. I have tried a bunch of scripts off the net, but somewhere I am missing something. Yours is getting me the closest though, but I get the below when running it:

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not
null or empty, and then try the command again.
At line:1 char:14
+ ... et-VM -Name (Get-Content -Path C:\Users\anton.louw\Desktop\Sockets.xl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

0 Kudos
scott28tt
VMware Employee
VMware Employee

Moderator: Moved to PowerCLI Discussions


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

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

From that error message, I understand that your input file is an XLSX file?
In that case, the Get-Content of course does not work.
You will need the Import-Excel cmdlet from the ImportExcel module (do you have that installed?).

In that case, the Import-Excel will result in an array, and you will need to specify the column in that spreadsheet that contains the names of the VMs.
Which column is that?
Assuming it is 'vmName', the start of the script would be something like

$vmNames = Import-Excel -Path .\myExcel.xlsx | Select -ExpandProperty vmName 
Get-VM -Name $vmNames ...


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

0 Kudos
Anton_Louw
Contributor
Contributor

Hi @LucD 

Apologies, I should have pasted it as a txt. I tried the xlsx file because I got the same error message with the txt. 

I will try with the xlsx now again with your updated lines and let you know 🙂

Thanks

0 Kudos
LucD
Leadership
Leadership

It should work with a TXT file as well.
Are there perhaps any blank lines in that TXT file?


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

0 Kudos
Anton_Louw
Contributor
Contributor

I double checked the TXT file, there are no blank lines. So with the updated script I get info in the PowerCLI window, eg>

Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
VM01 PoweredOn 1 0,500

 

The only issue is, it does not seem to want to display the cores per socket, and the report is blank when it finishes the last step 

Below is what I am running:

$vmNames = Import-Excel -Path C:\Users\anton.louw\Desktop\Sockets.xlsx | Select -ExpandProperty vmName
Get-VM -Name $vmNames
Select Name,
       @{N='Sockets';E={$_.ExtensionData.Config.Hardware.NumCpu}},
       @{N='CoresPerSocket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}} |
Export-Csv -Path C:\Users\anton.louw\Desktop\report.csv -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership

That doesn't seem to be the output the script should be producing.
And it looks as if you forgot the pipeline symbol at the end of the Get-VM line.

$vmNames = Import-Excel -Path C:\Users\anton.louw\Desktop\Sockets.xlsx | Select -ExpandProperty vmName
Get-VM -Name $vmNames |
Select Name,
       @{N='Sockets';E={$_.ExtensionData.Config.Hardware.NumCpu}},
       @{N='CoresPerSocket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}} |
Export-Csv -Path C:\Users\anton.louw\Desktop\report.csv -NoTypeInformation -UseCulture


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

0 Kudos