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 [...]
Is it just me? (Or does PowerShell remind you of SQL?)
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 [...]
Executing SQL the Right Way in PowerShell
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: [...]
PowerShell Tools and Books That I Use
Tools I Use (note…these are all free!): PowerGUI Script Editor (I haven’t ever gotten the hang of PowerGUI itself) Powershell Community Extensions 1.2 (PSCX) PowerTab SQL PowerShell Extensions 1.61 (SQLPSX) PrimalForms Community Edition Books: PowerShell In Action by Bruce Payette Professional Windows PowerShell Programming: Snapins, Cmdlets, Hosts and Providers by Arul Kumaravel et. al. Mastering [...]
Getting Scheduled Tasks in PowerShell
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).