miikeb
Contributor
Contributor

Report vm number of CPU Sockets and Cores per Socket

I am trying to have a script export the number of CPU sockets and then cores per socket.  Here is a snippet of the script.  When I run it the csv output vCPU ends up being a total count of the vCPU cores (so sockets x cores) instead of the number of CPUs and the vCPU cores ends up blank.

Anyone know what I am doing wrong here?

foreach ($vm in (get-vm)) { 

     $properties = @{'VMName'=$vm.Name; 

           'IP Address'= $vm.Guest.IPAddress[0]; #$VM.ExtensionData.Summary.Guest.IpAddress           

           'vCPU'= $vm.NumCPU;

           'vCPU Cores'= $vm.NumCoresPerSocket;

           'RAM(GB)'= $vm.MemoryGB; 

6 Replies
kunaludapi
Expert
Expert

This link will be helpful

PowerCLI - Get number of cores per cpu and number of sockets

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
miikeb
Contributor
Contributor

Thank you, when I run that script alone it works fine.

How can I incorporate that in to mine though? Do I need to do something instead of get-vm?

This is what I just tried, and the vcpu and vcpu cores came back blank

function Get-VMinventory { 

function Get-RDMDisk { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $RDMInfo = Get-VM -Name $VMName | Get-HardDisk -DiskType RawPhysical, RawVirtual 

         $Result = foreach ($RDM in $RDMInfo) { 

          "{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)    

         } 

         $Result -join (", ") 

function Get-vNicInfo { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $vNicInfo = Get-VM -Name $VMName | Get-NetworkAdapter 

         $Result = foreach ($vNic in $VnicInfo) { 

           "{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type) 

         } 

         $Result -join (", ") 

function Get-InternalHDD { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $VMInfo = Get-VMGuest -VM $VMName # (get-vm $VMName).extensiondata 

         $InternalHDD = $VMInfo.ExtensionData.disk  

         $result = foreach ($vdisk in $InternalHDD) { 

           "{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int]) 

         } 

         $result -join (", ") 

   foreach ($vm in (get-view -viewtype VirtualMachine)) { 

     $properties = @{'VMName'=$vm.Name; 

           'IP Address'= $vm.Guest.IPAddress[0]; #$VM.ExtensionData.Summary.Guest.IpAddress           

           'vCPU'= $vm.config.hardware.NumCPU;

           'vCPU Cores'= $vm.config.hardware.NumCoresPerSocket;

           'RAM(GB)'= $vm.MemoryGB; 

           'Total-HDD(GB)'= $vm.ProvisionedSpaceGB -as [int]; 

           'HDDs(GB)'= ($vm | get-harddisk | select-object -ExpandProperty CapacityGB) -join " + "           

           'Datastore'= (Get-Datastore -vm $vm) -split ", " -join ", "; 

           'Partition/Size' = Get-InternalHDD -VMName $vm.Name 

           'Operating System'= $vm.guest.OSFullName;  

           'Hardware Version'= $vm.Version;    

           'VMX' = $vm.ExtensionData.config.files.VMpathname; 

           'VMDK' = ($vm | Get-HardDisk).filename -join ", "; 

           'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus; 

           'VMTools Ver' = $vm.ExtensionData.Guest.ToolsVersion;    

           'SnapShots' = ($vm | get-snapshot).count; 

           'DataCenter' = $vm | Get-Datacenter; 

           'vNic' = Get-VNICinfo -VMName $vm.name; 

           'PortGroup' = ($vm | Get-NetworkAdapter).NetworkName -join ", "; 

           'RDMs' = Get-RDMDisk -VMName $VM.name 

           } 

     $obj = New-Object -TypeName PSObject -Property $properties

     Write-Output $obj | select-object -Property 'VMName', 'IP Address', 'Operating System', 'vCPU', 'vCPU Cores', 'RAM(GB)', 'Total-HDD(GB)' ,'HDDs(GB)', 'Datastore', 'Partition/Size', 'Hardware Version', 'VMX', 'VMDK', 'VMTools Status', 'VMTools Ver', 'SnapShots', 'DataCenter', 'vNic', 'PortGroup', 'RDMs'

   } 

Get-VMinventory | Export-Csv "C:\ppi\VM-report.csv" -NoTypeInformation -UseCulture

0 Kudos
kunaludapi
Expert
Expert

function Get-VMinventory { 

function Get-RDMDisk { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $RDMInfo = Get-VM -Name $VMName | Get-HardDisk -DiskType RawPhysical, RawVirtual 

         $Result = foreach ($RDM in $RDMInfo) { 

          "{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)    

         } 

         $Result -join (", ") 

function Get-vNicInfo { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $vNicInfo = Get-VM -Name $VMName | Get-NetworkAdapter 

         $Result = foreach ($vNic in $VnicInfo) { 

           "{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type) 

         } 

         $Result -join (", ") 

function Get-InternalHDD { 

   [CmdletBinding()] 

   param ( 

     [Parameter(Mandatory=$True)] 

     [string[]]$VMName 

     ) 

         $VMInfo = Get-VMGuest -VM $VMName # (get-vm $VMName).extensiondata 

         $InternalHDD = $VMInfo.ExtensionData.disk  

         $result = foreach ($vdisk in $InternalHDD) { 

           "{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int]) 

         } 

         $result -join (", ") 

   foreach ($vm in (get-vm)) { 

     $props = @{'VMName'=$vm.Name; 

           'IP Address'= $vm.Guest.IPAddress[0]; #$VM.ExtensionData.Summary.Guest.IpAddress 

           'PowerState'= $vm.PowerState; 

           'Domain Name'= ($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.';           

           #'vCPU'= $vm.NumCpu;

           'vCPU'= $vm.ExtensionData.config.hardware.NumCPU;

           'vCPU Cores'= $vm.ExtensionData.config.hardware.NumCoresPerSocket;

           'RAM(GB)'= $vm.MemoryGB; 

           'Total-HDD(GB)'= $vm.ProvisionedSpaceGB -as [int]; 

           'HDDs(GB)'= ($vm | get-harddisk | select-object -ExpandProperty CapacityGB) -join " + "           

           'Datastore'= (Get-Datastore -vm $vm) -split ", " -join ", "; 

           'Partition/Size' = Get-InternalHDD -VMName $vm.Name 

           'Real-OS'= $vm.guest.OSFullName; 

           'Setting-OS' = $VM.ExtensionData.summary.config.guestfullname; 

           'EsxiHost'= $vm.VMHost; 

           'vCenter Server' = ($vm).ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443") 

           'Hardware Version'= $vm.Version; 

           'Folder'= $vm.folder; 

           'MacAddress' = ($vm | Get-NetworkAdapter).MacAddress -join ", "; 

           'VMX' = $vm.ExtensionData.config.files.VMpathname; 

           'VMDK' = ($vm | Get-HardDisk).filename -join ", "; 

           'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus; 

           'VMTools Version' = $vm.ExtensionData.Guest.ToolsVersion; 

           'VMTools Version Status' = $vm.ExtensionData.Guest.ToolsVersionStatus; 

           'VMTools Running Status' = $vm.ExtensionData.Guest.ToolsRunningStatus; 

           'SnapShots' = ($vm | get-snapshot).count; 

           'DataCenter' = $vm | Get-Datacenter; 

           'vNic' = Get-VNICinfo -VMName $vm.name; 

           'PortGroup' = ($vm | Get-NetworkAdapter).NetworkName -join ", "; 

           'RDMs' = Get-RDMDisk -VMName $VM.name 

           } 

     $obj = New-Object -TypeName PSObject -Property $Props 

     Write-Output $obj | select-object -Property 'VMName', 'IP Address', 'Domain Name', 'Real-OS', 'vCPU', 'vCPU Cores', 'RAM(GB)', 'Total-HDD(GB)' ,'HDDs(GB)', 'Datastore', 'Partition/Size', 'Hardware Version', 'PowerState', 'Setting-OS', 'EsxiHost', 'vCenter Server', 'Folder', 'MacAddress', 'VMX', 'VMDK', 'VMTools Status', 'VMTools Version', 'VMTools Version Status', 'VMTools Running Status', 'SnapShots', 'DataCenter', 'vNic', 'PortGroup', 'RDMs' # 'Folder', 'Department', 'Environment' 'Environment' 

   } 

Get-VMinventory  | Export-Csv "C:\ppi\VM-report.csv" -NoTypeInformation -UseCulture

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
esxi1979
Expert
Expert

kunaludapi‌  & LucD

Its a nice function Get-VMinventory

i have multiple vcenetrs & i want this function to be used on some vms from csv , is it possible  ?

The function itself has a get-vm,

foreach ($vm in (get-vm)) {

SO i tried to add my csv stuff in that but it got messes up..

Please  suggest

0 Kudos
kunaludapi
Expert
Expert

put your vmlist on txt file something like below.


foreach ($vm in (get-vm (Get-content c:\temp\vmlist.txt))) {

http://vcloud-lab.com

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
esxi1979
Expert
Expert

Thanks kunaludapi

0 Kudos