Template based parsing and progress bars

Working with wifi I have often needed to do a survey of the surroundings, and therefor I loved that windows 7 (maybe even Vista) introduced more advanced netsh with wifi support.

There’s a lot of useful information but it might be nice to have a more graphical overview. The thing is that a text blob like this is not very handy to work with.


Some time late last year I heard a guy from the powershell team on the Powerscripting podcast talk about ConvertFrom-String and the new template based parsing. And it occurred to me that you can combine this with a simple powershell progress bar (write-progress) to give a visual representation of signal strength.

Why not try it out

Ps> help ConvertFrom-String –online


This looks straight forward.

Executing the the above code resulted in


This looks great. The data is structured nicely in a easy to use form.

Now lets combine that with a progress bar. We need a while loop to keep the progress bar alive and a one second sleep timer is probably a good idea.

The essential part is just a foreach looping through the networks objects. We use Write-Progress with parameters SIGNAL strength as PercentComplete and SSSID as Activity.

ise progress bars

It looks great in ISE and even works in the shell

shell progress

How cool is that?

The bright reader might have spotted an obvious flaw in the first template. It doesn’t handle networks with multiple radios e.g. a network with both a 2.4 ghz and 5 ghz and same ssid. And all the other nice information from netsh is simply ignored.

Second try

There’s a bit more markup here, and I admit it took me a few tries to get my head around the nested data structure. Look more closely at SSID 4 above, and how this have 2 BSSID’s, because of this they are marked with a *.

Now $Networks contain a little more complicated data structure


Though if we dive into it                             


It does look more like what we saw first. But with more info. And we can even dig into TDC-TC network and see each channel.


A slightly modified loop

And the percentage complete is a sub object. So we will need another loop to go through every BSSID attached to the SSID

The main thing here is of course using the template based parsing. It took me a few tries to figure it out, but it’s cool when it works and might be very useful in many other situations. The progress is just a hack that makes the presentation a little more fun.


Contact me

Twitter @mrhvid
Web Jonas.SommerNielsen.dk

4 thoughts on “Template based parsing and progress bars

  1. Pingback: List users logged on to your machines » PowerShell.org

Comments are closed.