PowerShell Problem Solver: Let’s Figure it Out

As you might already know, I spend a lot of time involved in the PowerShell community. I keep tabs on a number of PowerShell-related forums. I speak with people when presenting at conferences, hear from people on Twitter and I receive email from time to time from IT pros looking for a little help. As you may have heard I am going to be devoting quite a bit of time and energy to expanding the PowerShell content and community here at Petri, so part of my master plan is to start a weekly series called the PowerShell Problem Solver, which will be posted every Wednesday morning on Petri.com

Introducing the PowerShell Problem Solver

The goal of this column is to take a question, topic or problem that I’ve come across and present a PowerShell solution to the problem. The problem might be a question I saw in an online forum, something that came to me via email, or even a problem that I faced personally. The solution may be a complete PowerShell script or advanced function. Or it may be an annotated example that explains a troublesome concept. I’m assuming that if one person has a question someone else is thinking about the same problem.
I want this series to be meaningful to the work you are doing in PowerShell today. One way you can participate, as well as get some help on your PowerShell questions is to use the PowerShell forum on Petri.com. I encourage you to visit the Petri PowerShell forum if you have a PowerShell related question or problem. I’ll do my best, along with other forum members, to help answer your question. And just maybe your question will be the inspiration for a PowerShell Problem Solver article.

PowerShell forum
The Petri PowerShell forum can be a great place to get answers to your Windows PowerShell questions. (Image: Jeff James)

PowerShell Isn’t Always the Answer

With all of that said, I want to take a moment to share what might be a rather counterproductive statement: Sometimes PowerShell is not the answer. I’m a big proponent of the right tool for the job, and for Windows-focused IT Pros that often means PowerShell. But I know we will face problems where PowerShell is not the right tool. As an example, there is a recent discussion thread in the PowerShell forum here about using PowerShell to programmatically run an MSI installation in an unintended fashion such as a PowerShell computer start up script.

After a bit of research and testing, I came to the conclusion that PowerShell wasn’t going to be the right tool for job. While PowerShell can run an MSI command and get it to at least start, not every package is built the same. In this situation, I suspect there is something in the way the package is built that is incompatible with a remote PowerShell session. It isn’t that something is “wrong” with PowerShell. But there are many legacy commands and technologies that were designed with a specific paradigm in mind. Most of the time PowerShell can adapt, but sometimes it can’t. When figuring out a PowerShell problem often the first question should be, “Is PowerShell the right tool?” I have no problem recommending a command line utility, or even an old-fashioned batch file if it gets the job done so you can go home. I often find that the answer is Group Policy. I am often amazed by the tasks IT Pros undertake with a script when all that is really required is a Group Policy setting. Have a GPO related question? Use the Petri GPO Forum.
Another potential stumbling block in solving problems is that not every PowerShell command is equal. Even from Microsoft, you will find the quality and design of PowerShell commands and modules varies widely. For example, even though there are cmdlets for SharePoint and SQL Server that ostensibly come from Microsoft, the respective product teams are responsible for their PowerShell implementations and their results may vary based on your experience with the core PowerShell cmdlets. Then you have other vendors offering PowerShell solutions which may or may not behave the way you expect. We may find that the root cause of your PowerShell problem is in the implementation and not necessarily the core management engine.
Finally, solving PowerShell problems simply means reading help. You have at your fingerprints very complete help about each cmdlet including details about each parameter and often several fully explained examples. Again, I’ve come across problems which weren’t really problems if the poster had taken time to read full help and examples for the cmdlet they were trying to use. Of course, if there is something in the documentation or example that you don’t understand then that is a problem and I’m eager to help.

Are you ready to solve some PowerShell problems?

If you have something that is giving you fits, I hope you’ll post in the Petri PowerShell forum. Include what you are trying to accomplish and what steps or commands you’ve tried. Be sure to include your PowerShell version and operating system. This helps me and other forum members to attempt to duplicate your problem. If something doesn’t work, be sure to include error messages. I get little frustrated when people post a problem descripting saying “it doesn’t work” with no error messages. Of course if “it doesn’t work” means your commands are completing without error but you aren’t getting the result you expect, that is a different type of problem so please mention that as well.
I think we learn best by overcoming obstacles and solving problems. Learning PowerShell and improving your proficiency should be no different.