Adding Line Numbers to Native Command Output

One of the great things about Powershell is that you can use all your standard command line tools, such as ipconfig and net.exe. The only issue is that these tools output text and Powershell works with objects.

The output of commands such as ipconfig is actually an array.

PS 24 >  (ipconfig).GetType().BaseType.FullName 

Each item in that array is a string

PS 31 >  (ipconfig)[4].gettype().FullName 

So really you end up with an array of strings and if you know the indexes of that array, you can work with much more specific data. For example:

PS 58 >  (ipconfig)[7] 
   IPv4 Address. . . . . . . . . . . :

But how do you know that this is line 7, or the 7th item in the array. You can run the command and count lines and guess, or you can do something like this:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: