PowerShell: Use Regex to Select IPv4 Patterns

# This example shows how to obtain ip address of the $env:logonserver
$logonServerIP=nltest /DSGETDC:
$regexIP = [regex] "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
$regexIP.Matches($logonServerIP).Value

Leave a Reply

Your email address will not be published. Required fields are marked *