VMware Cloud Community
COS
Expert
Expert
Jump to solution

Tally up the last 2 values and the total be the last column data

I have my script below...

$myCol = @()

foreach ($cluster in Get-Cluster)

    {

        foreach($vmhost in ($cluster | Get-VMHost))

        {

            foreach($vm in (Get-VM -Location $vmhost)){

                $VMView = $vm | Get-View

                $VMSummary = "" | Select ClusterName,VMName,VMSockets,VMCores

                $VMSummary.ClusterName = $cluster.Name

                $VMSummary.VMName = $vm.Name

                $VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu

                $VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket

                $myCol += $VMSummary

            }

        }

    }

    $myCol | Export-Csv C:\Temp\VM-cpu-core.txt

I get the values like this....

"DMZ","Trend Micro Deep Security (1)","2","1"

"DMZ","Guest Introspection (1)","2","1"

The last 2 values are the CPU count and the CoresPerCPU.

Is it possible to take the last 2 values and multiply them together to get the total core count for the VM and make/append it as the last value in the data line like this....

"DMZ","Trend Micro Deep Security (1)","2","1","2"

"DMZ","Guest Introspection (1)","2","1","2"

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I'm afraid you're not interpreting the NumCpu property correctly.
In the VirtualHardware object, the NumCpu property is described as "Number of virtual CPUs present in this virtual machine".

The corrected script, including the Sockets, Cores/Socket and total vCPU looks like this

$myCol = @()

foreach ($cluster in Get-Cluster)

{

   foreach ($vmhost in ($cluster | Get-VMHost))

   {

   foreach ($vm in (Get-VM -Location $vmhost))

   {

   $VMView = $vm | Get-View

   $VMSummary = "" | Select ClusterName, VMName, VMSockets, VMCores, VMvCPU

   $VMSummary.ClusterName = $cluster.Name

   $VMSummary.VMName = $vm.Name

   $VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu / $VMView.Config.Hardware.NumCoresPerSocket

   $VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket

   $VMSummary.VMvCPU = $VMView.Config.Hardware.NumCpu

   $myCol += $VMSummary

   }

   }

}

$myCol | Export-Csv C:\Temp\VM-cpu-core.txt


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I'm afraid you're not interpreting the NumCpu property correctly.
In the VirtualHardware object, the NumCpu property is described as "Number of virtual CPUs present in this virtual machine".

The corrected script, including the Sockets, Cores/Socket and total vCPU looks like this

$myCol = @()

foreach ($cluster in Get-Cluster)

{

   foreach ($vmhost in ($cluster | Get-VMHost))

   {

   foreach ($vm in (Get-VM -Location $vmhost))

   {

   $VMView = $vm | Get-View

   $VMSummary = "" | Select ClusterName, VMName, VMSockets, VMCores, VMvCPU

   $VMSummary.ClusterName = $cluster.Name

   $VMSummary.VMName = $vm.Name

   $VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu / $VMView.Config.Hardware.NumCoresPerSocket

   $VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket

   $VMSummary.VMvCPU = $VMView.Config.Hardware.NumCpu

   $myCol += $VMSummary

   }

   }

}

$myCol | Export-Csv C:\Temp\VM-cpu-core.txt


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

0 Kudos
COS
Expert
Expert
Jump to solution

"I'm afraid you're not interpreting the NumCpu property correctly."

Yup, you're right..........lol

0 Kudos