Mike's PowerShell Musings

Menu

Archive of entries posted on September 2009

When writing a “get-” function in PowerShell, you often run into the issue of filtering your data. Do you want to include any filtering parameters? Do you want to allow lists of values? Do you want to provide “include” or “exclude” parameters? What about wildcards? I got tired of writing the same kind of code …

If you’re like me, you hate to do the same thing over and over. That’s what programming is for, right? To handle automating tedious procedures? Unfortunately, it’s not at all appropriate to run off and build an app every time you need to do the same thing 3 times. If you try that, you’ll have …

When preparing a PowerShell training class for a group of DBAs, I realized that there were some parallels between basic SQL and basic PowerShell commands. A (very) basic SQL statement has the form: SELECT <COLUMNS> FROM <TABLE> WHERE <CONDITION> ORDER BY <EXPRESSION> I noticed that a very common idiom for PowerShell pipelines* was: <data source …

We all know that using string concatenation (or substitution) in SQL is a “bad thing”. If you google “SQL Injection”, you’ll find hundreds of pages that tell you not to do things this way and that you need to use parameterized queries. However, I still see a lot of code in PowerShell that does this: …

There are a few approaches to manipulating scheduled tasks in PowerShell.

* WMI – Useful if you are only going to manipulate them via script. The tasks will not be visible in the control panel applet.
* SCHTASKS.EXE – Works ok, but has a somewhat arcane syntax, and is a text-only tool.
* Task Scheduler API -Best of both worlds, but only on Vista (not XP).

Why am I writing a blog about PowerShell? The answer is simple. I haven’t been as excited about a technology since I first learned SQL. PowerShell allows me to do my job in a much more consistent, flexible, and scalable way.