Skip to content

Instantly share code, notes, and snippets.

@StartAutomating
Created January 25, 2026 22:15
Show Gist options
  • Select an option

  • Save StartAutomating/e5d934b214ede1aa5092c12f700b781a to your computer and use it in GitHub Desktop.

Select an option

Save StartAutomating/e5d934b214ede1aa5092c12f700b781a to your computer and use it in GitHub Desktop.
Gist Get Me the CPU Speed
<#
.SYNOPSIS
Get the CPU Speed
.DESCRIPTION
Get the CPU Speed on Linux, MacOS, or Windows
.EXAMPLE
./GetCPUSpeed.ps1
#>
if ($executionContext.SessionState.PSVariable.Get('IsLinux').Value) {
Get-Content /proc/cpuinfo -Raw -ErrorAction SilentlyContinue |
Select-String "(?<Unit>Mhz|MIPS)\s+\:\s+(?<Value>[\d\.]+)" |
Select-Object -First 1 -ExpandProperty Matches |
ForEach-Object {
$_.Groups["Value"].Value -as [int]
}
} elseif ($executionContext.SessionState.PSVariable.Get('IsMacOS').Value) {
(sysctl -n hw.cpufrequency) / 1e6 -as [int]
} else {
$getCimInstance = $ExecutionContext.SessionState.InvokeCommand.GetCommand('Get-CimInstance','Cmdlet')
if ($getCimInstance) {
& $getCimInstance -Class Win32_Processor |
Select-Object -ExpandProperty MaxClockSpeed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment