Powershell to Validate IP Configuration (Address, Gateway, Subnet Mask, DNS)
I'm working on a VM deployment script for one of my customers. As you might expect, input validation is incredibly important, as we want to filter out a malformed configuration before starting the actual deployment. To that end, I put together a bit of PowerShell that I'm pretty proud of; this script does a basic sanity check on a network configuration . It does a fair amount of work. Firstly, it checks to ensure that the IP Address, Gateway, Subnet Mask, and all DNS Servers are being supplied as valid IP addresses. PowerShell makes this trivial to do, as you can cast a string as an [ipaddress] object and PowerShell will parse it for you. If it's a string that can't be parsed (such as [ipaddress]"JasonIsAwesome!" which is a string that most people would agree is inherently incomprehensible*), it'll throw an Exception and thus end the execution of the script. So, that most basic input validation is over in a blink... but wait, there's more! Since