PowerCLI

 View Only
Expand all | Collapse all

Get VM CPU, Sockets and Cores per socket details

  • 1.  Get VM CPU, Sockets and Cores per socket details

    Posted Nov 23, 2020 01:41 PM

    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



  • 2.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 23, 2020 01:46 PM

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



  • 3.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 23, 2020 02:05 PM

    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.



  • 4.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 23, 2020 02:18 PM

    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
    


  • 5.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 24, 2020 04:57 AM

    Hi  

    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



  • 6.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 24, 2020 07:42 AM

    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 ...


  • 7.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 24, 2020 07:55 AM

    Hi  

    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



  • 8.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 24, 2020 08:04 AM

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



  • 9.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 24, 2020 08:48 AM

    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



  • 10.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 24, 2020 09:38 AM

    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


  • 11.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 23, 2020 05:25 PM

    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

     



  • 12.  RE: Get VM CPU, Sockets and Cores per socket details

    Posted Nov 24, 2020 06:11 AM

    Moderator: Moved to PowerCLI Discussions