Test-IsValidIP

Test if an IP address has a valid format, IPv4 or IPv6

Function Test-IsValidIP {
    [CmdletBinding()]
    Param (
        [parameter(ValueFromPipeLine=$True,ValueFromPipeLineByPropertyName=$True)]
        [Alias("IP")]
        [string]$IPAddress
    )
 
    Process {
        Try {
            [ipaddress]$IPAddress | Out-Null
            Write-Output $True
        } Catch {
            Write-Output $False
        }
    }
}

Leave a Reply

Scroll to Top