Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dan1el42/e8b38f583f00972f80c9c80d4e82ac0d to your computer and use it in GitHub Desktop.
Save Dan1el42/e8b38f583f00972f80c9c80d4e82ac0d to your computer and use it in GitHub Desktop.
$csvFileName = 'C:\My\Input.csv'
# Example 3 - Using the -match operator with a more complex regular expression to extract the IP address
Import-Csv -Path $csvFileName |
ForEach-Object {
if ($PSItem.URL -match '(?<IPAddress>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})') {
$Matches.IPAddress
}
}
# Example 4 - Using the -match operator with a more regular expression to extract the IP address
# and casting to IPAddress to ensure we get a valid IP address
Import-Csv -Path $csvFileName |
ForEach-Object {
if ($PSItem.URL -match '(?<IPAddress>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})') {
([IPAddress] $Matches.IPAddress).IPAddressToString
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment