Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Original code from https://devblogs.microsoft.com/scripting/testing-rpc-ports-with-powershell-and-yes-its-as-much-fun-as-it-sounds/
- ## Showing here how to use regular expressions (regex) to match and tokenise strings in one operation via the $Matches built in variable
- ForEach ($strResult in $arrQuryResult)
- {
- ## ncacn_ip_tcp:grl-dc03[49668]
- If ($strResult -match "ip_tcp.*\[(\d+)\]" )
- {
- ## += on arrays/strings can be very slow! Use System.Collections.Generic.List & StringBuilder respectively
- ## the () in the regex above denote a matching group where the first will go into $Matches[1] which is a built in hash table containing the matched groups
- $arrPorts += $Matches[1]
- }
- }
Add Comment
Please, Sign In to add comment