Get the name of the VM Cluster, host name, CPU and carrots

Hello

All of the following code gives the expected results, except for the last line. I can't make it work. What I am doing wrong?

Get - VM | Select Name, @{N = 'Cluster'; {E = {Get-Cluster - VM $_}},

@{N = "ESX host"; {E = {Get-VMHost - VM $_}},

@{N = "NumCPU"; E = {Get-VMHost - VM $_______ |} Select NumCPU}},

@{N = "Kernels"; E = {Get-VMHost - VM $_______ |} Get - View). Hardware.CpuInfo.NumCpuCores}}

Thank you!

There was a missing (in front of your last Get-VMHost. Want to be as fair as the attribute NumCPU, not an object that contains an attribute NumCPU so I changed line 3 a little

Get - VM | Select Name, @{N = 'Cluster'; {E = {Get-Cluster - VM $_}},

@{N = "ESX host"; {E = {Get-VMHost - VM $_}},

@{N = "NumCPU"; E = {(Get-VMHost-VM $_).} NumCPU}},

@{N = "Kernels"; E = {(Get-VMHost-VM $_ |)} Get - View). Hardware.CpuInfo.NumCpuCores}}

If you use this for a large number of virtual machines, you can watch by optimizing a bit. Rather call 'Get-VMHost' several times you can restructure a bit then called this is only once

Get - VM | Select Name, @{N = 'Cluster'; {E = {Get-Cluster - VM $_}},

@{N = "ESX host"; E = {$Script: VMH = (Get-VMHost - VM $_); $Script: VMH.} Name}},

@{N = "NumCPU"; E = {$Script: VMH.} NumCPU}},

@{N = "Kernels"; E = {$Script: VMH.} ExtensionData.Hardware.CpuInfo.NumCpuCores}}

The 2nd piece of code is a little more than 2 x faster than the first since Get-VMHost is not be called multiple times

Another quick thing, if you are looking for the number of processors (i.e. how much taken) then replace $Script: VMH. NumCPU with $Script: VMH. ExtensionData.Hardware.CpuInfo.NumCpuPackages; the host object NumCPU attribute is actually the number of cores that can be a bit misleading

Tags: VMware

Similar Questions

Maybe you are looking for