Check-SubnetMask
Checks the given subnet mask for validity
param([string]$address = "")
function IsSubNetMaskValid { param([string]$IP)
$RegEx = "^(254|252|248|240|224|192|128).0.0.0$|^255.(254|252|248|240|224|192|128|0).0.0$|^255.255.(254|252|248|240|224|192|128|0).0$|^255.255.255.(255|254|252|248|240|224|192|128|0)$"
if ($IP -match $RegEx) {
return $true
} else {
return $false
}
}
try {
if ($address -eq "" ) { $address = read-host "Enter subnet mask to validate" }
if (IsSubNetMaskValid $address) {
"? subnet mask $Address is valid"
exit 0 # success
} else {
write-warning "Invalid subnet mask: $address"
exit 1
}
} catch {
"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}Specifies the subnet mask to check