I want to pass two arguements with a powershell-script.
This is the regular check
test = cmd /c echo scripts\test.ps1 ; exit($lastexitcode) | powershell.exe -command -
This is the idea that i want. To set warning and critical.
test = cmd /c echo scripts\test.ps1 -w 10 -c 50 ; exit($lastexitcode) | powershell.exe -command -
If warning is set to over 10 then it will return exit 1
If critical is set over 50 then it will return exit 2
Not sure howto do this in my script.
Here is how it looks now.
$condition = (Get-Service | Where-Object Status -eq "Running").Count
if ($argument warn) {
Write-Output "Warning:" $condition
exit 1
}
ElseIf ($argument critical) {
Write-Output "Critical:" $condition
exit 2
}
Although I'm not quite sure if this is what you mean, but you can start the script with a param() block so it accepts arguments like
param (
[int]$WarningLevel = 0,
[int]$CriticalLevel = 0
)
$condition = (Get-Service | Where-Object {$_.Status -eq "Running"}).Count
if ($CriticalLevel -gt 0 -and $condition -gt $CriticalLevel) {
Write-Output "Critical: Way too many proc's: $condition"
Exit 2
}
elseif ($WarningLevel -gt 0 -and $condition -gt $WarningLevel) {
Write-Output "Warning: proc's filling up: $condition"
Exit 1
}
Write-Output "All OK"
Exit 0