This is a quick tip for the situations where you are building a function with an IP address parameter. There are many ways of validating that a valid IP address are filled out, but this is by far the easiest.
function Invoke-MyFunction { [CmdletBinding()] param ( [Parameter()] [ipaddress] $IPAddress ) Write-Output $IPAddress }
That’s it. Only a valid IP address are now allowed in the -IPAddress parameter.
Thanks for the refresh! I forgot about this ! Very handy indeed 🙂
LikeLike
Yes, I had forgot it myself when I needed it. So I thought I’d blog about it. Just as much for myself so I don’t forget again 😀
LikeLike