VMware Cloud Community
Jstrat31
Enthusiast
Enthusiast

Looking for a way to compare vCPU and Sockett count on the VM and what the Windows guest lists.

Hello everyone,

I'm looking for a way to compare a single VM's hardware settings for vCPU and Socket count on the VM config and in the Windows guest and have powershell send an email if they are different.

I can get the VM vCPU info I need using this:

Get-VM "VMNAME" |

Select Name,NumCpu,CoresPerSocket,

    @{N='CpuSockets';E={$_.NumCpu/$_.CoresPersocket}}

but I'm having a heck of a time getting the vCPU and Socket count form inside the quest. I basically want to see the same thing taskmgr lists.

pastedImage_0.png

I've tried a view WMIC scripts but they are not getting me the info I need.

I was hoping to use the Invoke-VMScript cmd to get the windows guest info.

Any help would be appreciated.

Thanks!!

Jason Hartley VMware Systems Specialist "Develop the skill of sensing problems when they are still small and taking care of them before they become intractable"—Robert Greene http://privatecloudky.com/
Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

You could use Invoke-VMScript like this.
It assumes that PowerShell is present in the Guest OS.

$vmName = 'MyVM'

$user = 'domain\user'

$pswd = 'VMware1!'


$code = @'

Get-CimInstance Win32_ComputerSystem |

Select NumberOfLogicalProcessors, NumberOfProcessors |

ConvertTo-Csv -NoTypeInformation

'@


$sInvoke = @{

    VM = $vmName

    ScriptText = $code

    ScriptType = 'Powershell'

    GuestUser = $user

    GuestPassword = $pswd

}

Invoke-VMScript @sInvoke |

select -ExpandProperty ScriptOutput |

ConvertFrom-Csv


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

Reply
0 Kudos
Jstrat31
Enthusiast
Enthusiast

Thanks for the quick reply. I will give that a shot.

So far I've managed to put this together to use PowerCLI to at least give me the info I'm looking for. Now I just have to get it to compare any differences.

I'm not the best with powershell so I'm sure the script is ugly lol.

$code = @'

$cs = Get-WmiObject -Class Win32_ComputerSystem

$Sockets=$cs.NumberOfProcessors

$Cores=$cs.NumberOfLogicalProcessors

$vm = "SRV-P21_SQL"

#OS Guest CPU variables

$oscore = Write-Host ("O/S Reported Cores: " + $Cores)

$ossocket = Write-Host ("O/S Reported Sockets: " + $Sockets)

'@

$result = Invoke-VMScript -VM VMNAME -ScriptText $code -GuestUser user -GuestPassword pass -ScriptType PowerShell | Select -ExpandProperty ScriptOutput

Write-host "####O/S Reported Cores and Sockets####"

$result

#VM Config CPU info via vCenter

Write-host "###vCenter Reported Cores and Sockets###"

Get-VM SRV-P21_SQL | Select Name,NumCpu,CoresPerSocket,

@{N='CpuSockets';E={$_.NumCpu/$_.CoresPersocket}}

Jason Hartley VMware Systems Specialist "Develop the skill of sensing problems when they are still small and taking care of them before they become intractable"—Robert Greene http://privatecloudky.com/
Reply
0 Kudos
Jstrat31
Enthusiast
Enthusiast

The above script I posted gives me this output

####O/S Reported Cores and Sockets####

O/S Reported Cores: 10

O/S Reported Sockets: 2

###vCenter Reported Cores and Sockets###

Name        NumCpu CoresPerSocket CpuSockets

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

SRV-P21_SQL     10              5          2

I just need to

A. make thing prettier.

B. try and have powershell compare the two and if there are any differences send an email.

Jason Hartley VMware Systems Specialist "Develop the skill of sensing problems when they are still small and taking care of them before they become intractable"—Robert Greene http://privatecloudky.com/
Reply
0 Kudos
LucD
Leadership
Leadership

You could store the CPU count and the Core count in a PSCustomObject.
One PSCustomObject for the info from vCenter, and another one for the info coming from the Guest OS.

Then you could Compare-Object to verify that both are the same or not.

Some sample code


$obj1 = [PSCustomObject]@{

    Field1 = 1

    Field2 = 2

}

$obj2 = [PSCustomObject]@{

    Field1 = 1

    Field2 = 1

}

if(Compare-Object -ReferenceObject $obj1 -DifferenceObject $obj2 -Property $obj1.PSObject.Properties.Name){

    Write-Host "Objects are not equal"

}

else{

    Write-Host "Objects are equal"

}


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

Reply
0 Kudos