Get the CPU Speed on Linux, MacOS, or Windows
0
GetCPUSpeed.ps1
1<#
2.SYNOPSIS
3 Get the CPU Speed
4.DESCRIPTION
5 Get the CPU Speed on Linux, MacOS, or Windows
6.EXAMPLE
7 ./GetCPUSpeed.ps1
8#>
9if ($executionContext.SessionState.PSVariable.Get('IsLinux').Value) {
10 Get-Content /proc/cpuinfo -Raw -ErrorAction SilentlyContinue |
11 Select-String "(?<Unit>Mhz|MIPS)\s+\:\s+(?<Value>[\d\.]+)" |
12 Select-Object -First 1 -ExpandProperty Matches |
13 ForEach-Object {
14 $_.Groups["Value"].Value -as [int]
15 }
16} elseif ($executionContext.SessionState.PSVariable.Get('IsMacOS').Value) {
17 (sysctl -n hw.cpufrequency) / 1e6 -as [int]
18} else {
19 $getCimInstance = $ExecutionContext.SessionState.InvokeCommand.GetCommand('Get-CimInstance','Cmdlet')
20 if ($getCimInstance) {
21 & $getCimInstance -Class Win32_Processor |
22 Select-Object -ExpandProperty MaxClockSpeed
23 }
24}