# get-uint16maxvalue.ps1
# Minvalue sample using PowerShell
# Thomas Lee - tfl@psp.co.uk
# Create test a value in range of uint16
[int] $IntegerValue = 1216
[system.int16] $uIntegerValue = 0
# Print it out
"Test 1"
"Integer value = $Integervalue"
# Now test and print results
if ($integerValue -ge [System.uint16]::MinValue -and $integerValue -le [System.uint16]::MaxValue) {
$uIntegerValue = $integerValue
"The short value is: $uIntegerValue"
}
else
{
"Unable to convert {0} to a UInt16" -f $integerValue
}
""
# now test one out of range
"Test 2"
if (99999999 -ge [System.uint16]::MinValue -and 99999999 -le [System.uint16]::MaxValue) {
$uIntegerValue = 99999999
"The short value is: $uIntegerValue"
}
else
{
"Unable to convert {0} to a UInt16" -f 99999999
}
This script produces the following output
PSH [C:\foo]: .\get-uint16fields.ps1
Test 1
Integer value = 1216
The short value is: 1216
Test 2
Unable to convert 99999999 to a UInt16