Powershell

Robot avatar images lovingly delivered by Robohash.org.

Twizzle  •  16 Aug 2023   •    
Screenshot

Even though I work in "IT Support", I find that knowing how to code is important.  It makes my life easier and helps me get things done quicker.

The system that I support relies a lot on XML files for reporting.  They are the output of various timed jobs and scripts that run, collating data and test results, which all get uploaded to a central server and parsed for reports.  The issue is, that although I have access to the reports on the central system, I can't create my own.  Some of the data I want to see in the reports are hidden.

Over the years, I have used various programming languages to get at these XML files, extracting the data I need and output as CSV.  My usual tool of choice was VBScript, which iterated over a folder full of already downloaded XML files (via the Download Them All! Firefox extension), extracting the fields and values I needed.  It's a great sanity check tool when comparing against manually created and maintained spreadsheets.  After all, human error or forgetting to update something is easily done.

I have also created tools with Javascript and HTML, plus some self-hosted PHP scripts too.  I don't have access to a PHP environment for work, so host some simple parsing scripts myself on my own VPS.  No data is stored there, just processed and output.

My latest tool of choice has become Powershell.  It seems to allow me all of the benefits of VBScript, but with also being able to download or read/write local files too.  So rather than manually downloading XML files to parse, I can give it a CSV of targets to download from, ask it to download the file and then walk through the XML values I need, applying logic where required.  It doesn't seem to suffer from the same security worries or incompatabilities that Javascript or VBScript did.

However, I wish it was able to run a script and generate HTML output via a browser, but I am forced to create my output as HTML, save it as a file and load it up manually.  I am sure there will be an easier way to do this, but it works for what I need.

I had always resisted Powershell in the past, but I am getting to quite like it now.

Comments

One of my least favorite activities in SQL is to parse XML. One day, it took me the whole day to write nine lines of SQL to parse a table with a column formatted in XML. YUCK.

therealbrandonwilson  •  16 Aug 2023, 8:42 pm

I just ended up using Powershell to regex the values I needed from the XML file.
Look for <tag =“start”>(.*?) and then grab what I need from there, then repeat.
It’s a dirty way of doing things, but the XML files I work with are all slightly different, so I can’t guarantee the fields will be there that I need.

Robot avatar images lovingly delivered by Robohash.org.
Twizzle  •  17 Aug 2023, 3:05 pm

Discover more

Sourced from other writers across Lifelog

Ooops we couldn't find any related post...