Created
January 25, 2026 22:15
-
-
Save StartAutomating/e5d934b214ede1aa5092c12f700b781a to your computer and use it in GitHub Desktop.
Gist Get Me the CPU Speed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .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