# set your test exit code (0,1,2)
$exitCode = 0

switch ($exitCode) 
{ 
	0 { 
		Write-Host "[OK] Exit Code 0 delivers a green icon "
		exit 0
	} 
	1 { 
		Write-Host "[WARNING] Exit Code 1 delivers a yellow icon"
		exit 1
	} 
	2 { 
		Write-Host "[PROBLEM] Exit Code 2 delivers a red icon"
		exit 2
	} 
	default { 
		Write-Host "[PROBLEM] All other Exit Codes deliver a red icon"
		exit 2
	} 
}

CPU Leistung ermitteln und bei bei festgelegten Grenzwerten Administrator informieren.

$WARNLEVEL = 25
$CRITLEVEL = 80

$cpuusage = (Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average)

if ( ($cpuusage.average) -lt $WARNLEVEL ) {
	Write-Host "[OK] CPU usage is normal: "($cpuusage.average)"%"
	exit 0
}
elseif ( ($cpuusage.average) -gt $CRITLEVEL ) {
	Write-Host "[PROBLEM] CPU usage is high: "($cpuusage.average)"%"
	exit 2
}
else {
	Write-Host "[WARNING] CPU usage is getting high: "($cpuusage.average)"%"
	exit 1
}

RAM Speicherverbrauch ermitteln und den Administrator beim Erreichen von festgelegten Grenzwerten warnen.

$WARNLEVEL = 65
$CRITLEVEL = 80

$ramusage = gwmi -Class win32_operatingsystem | Select-Object @{Name = "MemoryUsage"; Expression = {"{0:N2}" -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}

if ( ($ramusage.MemoryUsage) -lt $WARNLEVEL ) {
	Write-Host "[OK] MEMORY usage is normal: "($ramusage.MemoryUsage)"%"
	exit 0
}
elseif (  ($ramusage.MemoryUsage) -gt $CRITLEVEL ) {
	Write-Host "[PROBLEM] MEMORY usage is high: "($ramusage.MemoryUsage)"%"
	exit 2
}
else {
	Write-Host "[WARNING] MEMORY usage is getting high: "($ramusage.MemoryUsage)"%"
	exit 1
}