February 2019
Intermediate to advanced
626 pages
15h 51m
English
The netstat command produces tab-delimited, fixed-width tables. The following example converts the active connections that list active TCP connections, as well as listening TCP and UDP ports, into an object.
A snippet of the output that the example is intended to parse is shown in the following code:
PS> netstat -anoActive Connections Proto Local Address Foreign Address State PID TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 124 TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4 TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING 4
When handling text such as this, a pattern based on white space (or not white space) can be used:
^\s*\S+\s+\S+
For each column, the following expression with a named group is created:
(?<ColumnName>\S+)\s+
The trailing \s+
Read now
Unlock full access