My PowerShell Troubleshooting Toolkit Expanded

Posted on January 20, 2015 by Jeff Hicks in PowerShell with 0 Comments

Update: January 28, 2015 – 11:00 AM MT – It has come to our attention that the original CSV file in this article unintentionally contained a malware payload. If you have already downloaded the original CSV file, you should delete it immediately. We have replaced the original CSV file with a new CSV file that is safe to download. As a gentle reminder, please test and scan downloads in a non-production environment before using.

Sincerely, the Petri IT Knowledgebase editorial staff.

Original post below.

A few months ago I posted a few articles on how to use PowerShell to build a troubleshooting toolkit. If you’re like me, then you’re often called upon to troubleshoot a computer problem. The call may come as part of your official job, or you may enjoy the privilege of being the resident expert for your family or neighborhood, which is certainly true in my case. Since writing this article series, I’ve revised my PowerShell tools, so let’s take a look.

Originally, I showed you a few different ways to build a toolkit. I’m not going to rehash that in this article. Personally, I think it is better to separate the download tool from the list of files. Stated differently, it’s much smarter to maintain the list of tools separately, rather than hard coding the list of tools. I use a CSV file for this, and this is the most current version of the CSV file that I use. You should save a copy locally. Feel free to add your own tools to the list.

Next, we need a PowerShell tool to process the list. I have made a few revisions to my original Get-MyTool function. Here’s version 2.0 of that function.

The primary change is the addition of a NoClobber parameter. This is the same parameter used by Out-File, where the parameter essentially means, “don’t overwrite any existing files.”

Sponsored

If I’ve already downloaded a file from the CSV file, then there’s no need to download it again. Here’s how it is called from the private download function:

Once the CSV file is revised, I can run the following command to only download the files that don’t already exist in the destination path:

Using Windows PowerShell to only download files that don't already exist in the destination path. (Image Credit: Jeff Hicks)

Using Windows PowerShell to only download files that don’t already exist in the destination path. (Image Credit: Jeff Hicks)

Or, you can run the following command to download tools directly:

Of course, I’ve also updated the function’s comment-based help.

Unfortunately, the Get-MyTool function can only process a single download at a time. That’s where I like using a workflow so that I can take advantage of parallelism. I added the same NoClobber feature to the workflow script, and I also added a parameter where you can specify the CSV file path. Here’s my updated workflow.

Sponsored

Here’s how you might use it:

The PowerShell script in action. (Image Credit: Jeff Hicks)

The PowerShell script in action. (Image Credit: Jeff Hicks)

This runs much faster because it downloads five files in parallel, although you can change that with the ThrottleLimit parameter. In terms of overall performance, the workflow option is the best choice I believe. I can’t think of much that I need to add to the function or workflow in terms of features. Now the only think I need to keep up to date is the CSV. In a future article, I’ll suggest one way to do just that.

Sponsored

Tagged with ,