PowerShell Function: Validate Subnet Mask

less than 1 minute read

This is a function I wrote couple of days ago for the Windows Build Scripts which I blogged yesterday. I think it is pretty cool so I’d like to blog this function individually:


It checks the following:

  • - if subnet mask is in numeric and consists 4 sections separated by "."
  • - If each section is ranged between 0 and 255
  • - convert it to binary format and make sure it is a valid subnet mask (first part consists all "1"s and second part consists all "0"s).

So here’s the usage:


This function can be downloaded HERE

Leave a comment