mardi 3 janvier 2017

Expanded properties not working in an "if" segment

Title may not be very helpful but I couldn't explain more without the code so here is the script I'm trying to run:

$CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors

(Get-Counter “\Process(w3wp*)\% Processor Time”).CounterSamples `
| Select-Object InstanceName,@{Name=”CPU”;Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 1)}} `
| ForEach-Object {

if ($_.CPU -gt 80){

Restart-Service -Name W3SVC

}
}

So the idea is to check for any iis processes that exceed 80% CPU usage and if so, restart the webservice. If I cut everything from ForEach-Object and down I get a list of my processes and the current usage of CPU in % in a list so that part works but I can't seem to get my if section to grab the CPU property.

Aucun commentaire:

Enregistrer un commentaire