2

I needed to get number of CPU processor speed as a number. I can't use any extra utility commands. I can use only cmd in Windows or Powershell.

wmic cpu get name | select -Skip 1 | %{$_.Split(' ')[5];} | %{$_.Substring(0, 3)}

Everything is performed correctly, except substring command enter image description here

Does it exist any easy approach to fix it? And why I get 4 warning for single value after split command?

2
  • Get-WmiObject Win32_Processor | Select-Object -Expand MaxClockSpeed Commented Oct 7, 2019 at 11:57
  • Or shortened (GWMI Win32_Processor).MaxClockSpeed or if you have at least PowerShell 3.0, (GCIM Win32_Processor).MaxClockSpeed. Commented Oct 7, 2019 at 12:01

1 Answer 1

5

Don't parse wmic output unless you're pressed for performance (and even then you should do (wmic cpu get maxclockspeed) -notlike '*maxclockspeed*' rather than parse the processor name output).

Use Get-WmiObject (all PowerShell versions) or Get-CimInstance (PowerShell v3 or newer) with the Win32_Processor class and expand the relevant property (MaxClockSpeed).

Get-CimInstance Win32_Processor | Select-Object -Expand MaxClockSpeed

The value is in MHz.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.