Reputation: 1828
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
Does it exist any easy approach to fix it? And why I get 4 warning for single value after split command?
Upvotes: 2
Views: 8034
Reputation: 200273
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.
Upvotes: 5