Read-Host is giving you a string. You're comparing it to a number, which is being implicitly converted to a string because it's on the right side of the comparison.
What you want to do is convert to a number first:
do
{
$setSubNetMask = 0
[int]$setSubNetMask = Read-Host -Prompt "Subnetmask (CIDR)"
if ($setSubNetMask -cge 32 -or $setSubNetMask -cle 2)
{
write-host "Felaktig CIDR (1-32)"
}
}
until ($setSubNetMask -cle 32 -and $setSubNetMask -cge 1)
PowerShell also supports ranges, so your conditionals might better be expressed as:
do
{
$setSubNetMask = 0
$setSubNetMask = Read-Host -Prompt "Subnetmask (CIDR)"
if (1..32 -notcontains $setSubNetMask)
{
write-host "Felaktig CIDR (1-32)"
}
}
until (1..32 -contains $setSubNetMask)
In PowerShell v3 and higher, you can reverse the order using the -in operator instead of -contains, depending on what feels more natural to you:
do
{
$setSubNetMask = 0
$setSubNetMask = Read-Host -Prompt "Subnetmask (CIDR)"
if ($setSubNetMask -notin 1..32)
{
write-host "Felaktig CIDR (1-32)"
}
}
until ($setSubNetMask -in 1..32)
Note that in these examples, I removed the [int] cast; it's not needed and the conversion will be done implicitly in either case.