I have a Powershell command (which checks % CPU usage of a process) that returns me 2 values (Instance name + CPU%). I want to return just ONE value (CPU%). What should I add to this script to do that? Example below:
$Processname = "slack"
$CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors
$Samples = (Get-Counter “\Process($Processname)\% Processor Time”).CounterSamples
$Samples | Select `
InstanceName,
@{Name=”CPU %”;Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 2)}}
The return value is:
InstanceName CPU %
------------ -----
slack 0
I want only the 0.