@@ -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