Skip to content
This repository was archived by the owner on May 2, 2021. It is now read-only.

Commit 11fdd3b

Browse files
committed
Parameter validation improved
1 parent 00a5d38 commit 11fdd3b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Scripts/Windows_NRPE/check_rds_device_cals.ps1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,28 @@ Param(
4848
Position=1,
4949
Mandatory=$true,
5050
HelpMessage='Number of free licenses before the status "critical" is returned.')]
51+
[ValidateScript({
52+
if($_ -ge $Warning)
53+
{
54+
throw "Critical value cannot be greater or equal than warning value!"
55+
}
56+
else
57+
{
58+
return $true
59+
}
60+
})]
5161
[Int32]$Critical,
5262

5363
[Parameter(
5464
Position=2,
5565
HelpMessage="Select your license key pack [KeyPackType --> 0 = unkown, 1 = retail, 2 = volume, 3 = concurrent, 4 = temporary, 5 = open license, 6 = not supported] (More details under: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383803%28v=vs.85%29.aspx)")]
66+
[ValidateRange(0,6)]
5667
[Int32[]]$KeyPackTypes=(0,1,2,3,4,5,6),
5768

5869
[Parameter(
5970
Position=3,
6071
HelpMessage="Select your product version [ProductVersionID --> 0 = not supported, 1 = not supported, 2 = 2008, 3 = 2008R2, 4 = 2012] (More details under: https://msdn.microsoft.com/en-us/library/windows/desktop/aa383803%28v=vs.85%29.aspx)")]
72+
[ValidateRange(0,4)]
6173
[Int32[]]$ProductVersionID=(0,1,2,3,4),
6274

6375
[Parameter(
@@ -76,7 +88,7 @@ Process{
7688
# If you are using PowerShell 4 or higher, you can use Get-CimInstance instead of Get-WmiObject
7789
$TSLicenseKeyPacks = Get-WmiObject -Class Win32_TSLicenseKeyPack -ComputerName $ComputerName -ErrorAction Stop
7890
} catch {
79-
Write-Host -Message "$($_.Exception.Message)" -NoNewline
91+
Write-Host -Object "$($_.Exception.Message)" -NoNewline
8092
exit 3
8193
}
8294

@@ -101,17 +113,17 @@ Process{
101113
# return critical OR warning OR ok
102114
if($AvailableLicenses -le $Critical)
103115
{
104-
Write-Host -Message "CRITICAL - $Message"
116+
Write-Host -Object "CRITICAL - $Message"
105117
exit 2
106118
}
107119
elseif($AvailableLicenses -le $Warning)
108120
{
109-
Write-Host -Message "WARNING - $Message"
121+
Write-Host -Object "WARNING - $Message"
110122
exit 1
111123
}
112124
else
113125
{
114-
Write-Host -Message "OK - $Message"
126+
Write-Host -Object "OK - $Message"
115127
exit 0
116128
}
117129
}

0 commit comments

Comments
 (0)