Wednesday, November 26, 2014

Testing IP address validity in PowerShell

There may come a time when you want to test if an IP-address is valid or not. Here's a simple PowerShell function that will do just that and return true or false.

Function Test-IPAddress {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$True, ValueFromPipelineByPropertyName=$True, Position=0)]
        [String]$IPAddress
    )
   
    Begin {
    }

    Process {
        Return ($IPAddress -As [IPAddress]) -As [Bool]
    }

    End {
    }
}



No comments:

Post a Comment