stash/Get-CpuFrequency.ps1

function Get-CpuFrequency {
  [CmdletBinding()]param()

  process {
    New-Delegate ntdll {
      int NtPowerInformation([int, ptr, int, buf, int])
    }

    $buf = [Byte[]]::new(0x18) # sizeof(PROCESSOR_POWER_INFORMATION)
    while ($ntdll.NtPowerInformation.Invoke(
      11, [IntPtr]::Zero, 0, $buf, $buf.Length
    ) -eq 0xC0000023) {
      [Array]::Resize([ref]$buf, ($buf.Length * 2))
    }

    $(for ($i, $sz, $cores = 0, 0x18, ($buf.Length / 0x18); $i -lt $cores; $i++) {
      $ppi = Read-DataValues $buf[0..($sz - 1)] -Map I6
      [PSCustomObject]@{
        Number           = $ppi[0]
        MaxMhz           = $ppi[1]
        CurrentMhz       = $ppi[2]
        MhzLimit         = $ppi[3]
        MaxIdleState     = $ppi[4]
        CurrentIdleState = $ppi[5]
      }
      $buf = $buf[$sz..$buf.Length]
    }) | Format-Table -AutoSize
  }
}