VMware Cloud Community
Squigglymonkey
Enthusiast
Enthusiast
Jump to solution

getting number cpu, cores and operating system

I found some scripting examples here for getting the number of cpu and number of cores, but I also need the operating system along with it.

 

	$result = @()
$vms = Get-view  -ViewType VirtualMachine
foreach ($vm in $vms) {
   	$obj = new-object psobject
   	$obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name
   	$obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU
   	$obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket
   	$result += $obj
  	
}
$result

 


I have tried adding in  $HostOperatingSystem = $vm.ExtensionData.Guest.GuestFullName with another $obj, but no OS, I tried just adding an $obj with $vm.guest.osfullname and still no OS.
What is the right way to do it?

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Did you try like this?

 

$result = @()
$vms = Get-view  -ViewType VirtualMachine
foreach ($vm in $vms) {
   	$obj = New-Object -TypeName psobject
   	$obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name
   	$obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU
   	$obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket
    $obj | Add-Member -MemberType NoteProperty -Name GuestOS -Value $vm.Guest.GuestFullName
   	$result += $obj
  	
}
$result | Format-Table -AutoSize

 


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

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

Did you try like this?

 

$result = @()
$vms = Get-view  -ViewType VirtualMachine
foreach ($vm in $vms) {
   	$obj = New-Object -TypeName psobject
   	$obj | Add-Member -MemberType NoteProperty -Name name -Value $vm.Name
   	$obj | Add-Member -MemberType NoteProperty -Name CPUSocket -Value $vm.config.hardware.NumCPU
   	$obj | Add-Member -MemberType NoteProperty -Name Corepersocket -Value $vm.config.hardware.NumCoresPerSocket
    $obj | Add-Member -MemberType NoteProperty -Name GuestOS -Value $vm.Guest.GuestFullName
   	$result += $obj
  	
}
$result | Format-Table -AutoSize

 


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

Squigglymonkey
Enthusiast
Enthusiast
Jump to solution

Yes that was what I tried, but I must have fat-fingered sometihng.

Thanks I have what I need now.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're welcome.
Btw, I just corrected the code above, the PassThrough on the 1st Add-Member line is not necessary.


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

Reply
0 Kudos