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?
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
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
Yes that was what I tried, but I must have fat-fingered sometihng.
Thanks I have what I need now.
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