Re-Thinking Positional Parameters

I mentioned in a previous post that I’ve recently changed my mind a bit about the Position parameter attribute. I guess technically it is the position parameter of the Parameter parameter attribute (i.e. there’s a parameter attribute called “Parameter” and it has a parameter called position). I don’t think you could come up with something …

Continue reading ‘Re-Thinking Positional Parameters’ »

You don’t need semicolons in multi-line hashtable literals.

This is not a world-changing topic, but I thought it was worth sharing. If you have written hashtable literals on a single line, you’ve seen this before: Sometimes, it makes more sense to write the hashtable over several lines, especially if it has several items. I’ve always written them like this: I was watching Don …

Continue reading ‘You don’t need semicolons in multi-line hashtable literals.’ »

Thoughts on PowerShell Performance

Last night Rob Campbell (@mjolinor) and I were talking after his presentation on performance when using Get-Content with -ReadCount and different string matching techniques and I realized it’s time to verbalize my thoughts on performance in PowerShell. Part 1 – It doesn’t matter When people ask me if PowerShell is fast, my first response is …

Continue reading ‘Thoughts on PowerShell Performance’ »

PowerShell Code Review Guidelines

I get asked to look at other people’s PowerShell code a lot at work, and I really enjoy it.  I also find myself looking at my “old” code from several years ago (back to 2007!) and think…there’s a lot of work to be done. To that end, I’ve compiled a list of “PowerShell code review …

Continue reading ‘PowerShell Code Review Guidelines’ »

7 Ingredients of Professional PowerShell Code

If you’ve been using PowerShell for any amount of time you’ve probably written a lot of code. Here are some guidelines I’ve come up with for what I consider “Professional” code. I should note that I’m assuming some basic things like correct verb-noun naming, commented code, reasonable variable names, etc. Also, the code should work! …

Continue reading ‘7 Ingredients of Professional PowerShell Code’ »

Invoke-SQLCmd considered harmful

I mentioned here that Invoke-SQLCmd (included in the SQLPS module for SQL Server) was susceptible to SQL-Injection attacks, but I haven’t demonstrated that or ever seen anyone show it. To do so, I’ll start with code out of the help for Invoke-SQLCmd.  Here’s the code (taken from here) Notice that the parameters are encoded in a …

Continue reading ‘Invoke-SQLCmd considered harmful’ »