Get full access to
Mastering Windows PowerShell Scripting - Second Edition
and 60K+ other titles, with a free 10-day trial of O'Reilly.
There are also live events, courses curated by job role,
and more.
Start your free trial
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 to an object.
A snippet of the output 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 whitespace (or not whitespace) 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+
is omitted for the ...
Get
Mastering Windows PowerShell Scripting - Second Edition
now with the O’Reilly
learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and
nearly 200 top publishers.
Start your free trial
Don’t leave
empty-handed
Get Mark Richards’s
Software Architecture Patterns
ebook to better understand how to design components—and how they should interact.
It’s yours, free.
Get it now
Check it out now
on O’Reilly
Dive in for free with a 10-day trial of the O’Reilly learning platform—then explore all the other resources our members count on to build skills and solve problems
every day.
Start your free trial
Become a member now