VMware Cloud Community
Azarou
Enthusiast
Enthusiast
Jump to solution

[Help] CPU type script

Hi Guys,

I am stucket with a script that can  display usage of CPU by processor type and % of host using AMD for all host attached to a vcenter.

Is their my little script...

$TotalCpu = (Get-VMhost | where {$_.Hardware.CpuPkg[0].Description -match 'Intel'} | Measure-Object -Property CpuTotalMhz -Sum).Sum

Write-Host  $TotalCpu MHZ

i also want to know if there is a way to have percentage of host using AMD and intel.

Already try that script from alan ( working great)

Get-VMHost | Sort Name | Get-View | Select Name, @{N=Cluster;E={Get-Cluster -VMHost (Get-VMHost $_.Name)}},@{N=CPU;E={$_.Hardware.CpuPkg[0].Description}}

But have no idea how to extract my precious Smiley Wink

If someone can help ( Great Lucd are u there ?)

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You mean something like this ?

$esx = Get-VMHost

$totInt = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'Intel'}

$totAMD = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'AMD'}

Write-Output "Total ESXi : $($esx.Count)"

Write-Output "Total Intel: $('{0:p}' -f ($totInt/$esx.Count))"

Write-Output "Total AMD  : $('{0:p}' -f ($totAMD/$esx.Count))"


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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

You mean something like this ?

$esx = Get-VMHost

$totInt = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'Intel'}

$totAMD = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'AMD'}

Write-Output "Total ESXi : $($esx.Count)"

Write-Output "Total Intel: $('{0:p}' -f ($totInt/$esx.Count))"

Write-Output "Total AMD  : $('{0:p}' -f ($totAMD/$esx.Count))"


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

Reply
0 Kudos
Azarou
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

Thanks for your reply, still got the same error ...

Impossible d'indexer dans un tableau Null.

Au niveau de D:\Desktop\amdintel.ps1 : 3 Caractère : 43

+ $totInt = $esx | Where{$_.Hardware.CpuPkg[ <<<< 0].Description -match 'Intel'}

    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException

    + FullyQualifiedErrorId : NullArray

Au niveau de D:\Desktop\amdintel.ps1 : 4 Caractère : 43

+ $totAMD = $esx | Where{$_.Hardware.CpuPkg[ <<<< 0].Description -match 'AMD'}

    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException

    + FullyQualifiedErrorId : NullArray

Any idea ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Oops, forgot ExtensionData.

I updated the script above


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

Reply
0 Kudos
Azarou
Enthusiast
Enthusiast
Jump to solution

Still not Smiley Sad

L'appel de la méthode a échoué parce que [System.Object[]] ne contient pas de méthode nommée « op_Division ».

Au niveau de D:\Desktop\amdintel.ps1 : 7 Caractère : 21

+ '{0:p}' -f ($totInt/ <<<< $esx.Count)

    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

Total Intel:

L'appel de la méthode a échoué parce que [System.Object[]] ne contient pas de méthode nommée « op_Division ».

Au niveau de D:\Desktop\amdintel.ps1 : 8 Caractère : 21

+ '{0:p}' -f ($totAMD/ <<<< $esx.Count)

    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

Reply
0 Kudos
Azarou
Enthusiast
Enthusiast
Jump to solution

Hi,

I found the trick thanks for your help. the error ( i thought ) was about the TotInt variable ( String ) and it cannot be divided by a number ( .count)

So i modified The script like that work well Smiley Wink:

$esx = Get-VMHost

$totInt = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'Intel'}

$totAMD = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'AMD'}

$Intel = $(100*$totInt.Count/$esx.Count)

$Amd = $(100*$totAMD.Count/$esx.Count)

Write-Output "Total ESXi Intel : $($totInt.Count)"

Write-Output "Total ESXi AMD   : $($totAMD.Count)"

Write-Output "ESXi Intel : $Intel  %"

Write-Output "ESXi AMD   : $Amd  % "

Thanks again great Lucd

Reply
0 Kudos
Azarou
Enthusiast
Enthusiast
Jump to solution

$esx = Get-VMHost

$totInt = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'Intel'}

$totAMD = $esx | Where{$_.ExtensionData.Hardware.CpuPkg[0].Description -match 'AMD'}

Write-Output "Total ESXi : $($esx.Count)"

Write-Output "Total Intel: $('{0:p}' -f ($totInt.count/$esx.Count))"

Write-Output "Total AMD  : $('{0:p}' -f ($totAMD.count/$esx.Count))"

Corrected

Reply
0 Kudos