Ok yes.

I’m being dramatic.  But I got your attention!

If you’ve worked on ANY level with Microsoft SQL Server 2008 and SQL Server 2008R2 you’ll know there are Windows Powershell Cmdlets.   The problem is it’s via “MiniShell” which is a sort of bastardized version of Powershell customized for SQL.

Well not REALLY but there is no shortcut for it.

No wait, I lied.  There is.  But it’s shortcut to an evil compiled “Quasi” Powershell session.   But it DOES use snapins.  But when you’re IN the “Mini-Shell” (Strikes me as “Mini-Me” accomplice to Dr. Evil) it won’t LET you run the “useful stuff” like “GET-PSSNAPIN”

But AHA! It *IS* using Snapins and those Snapins ARE Registered.

So by opening Windows Powershell and keying in

GET-PSSNAPIN –Registered

We get a handy output like this


So we could just add this our Profile but today I would like to just make a CUSTOM Powershell session with a Shortcut.

“Just cuz!”

So if you keyed in Powershell.exe /? within Cmd.exe or Powershell.exe you’ll see a pile of useful parameters you can use.  These are especially useful if you intend to schedule Powershell scripts as a task.  Today we’re just going to leverage the “-command” and “-noexit” parameters as we create a new Shortcut in Windows to launch our new Custom shell.

So within Windows on the Desktop, we’re just going to Right Click and choose “New Shortcut” which will launch that old familiar Wizard.  We’re going to Browse to “C:WindowsSystem32WindowsPowershellv1.0powershell.exe”




Once we have the shortcut selected, let’s “NEXT” and name that “SQL Powershell Console” (You could name it Ernie or Joey, but that might be more confusing later on when you need to use it)

After you complete, pull up the Properties on your new shortcut and you’ll to add the following info after “Powershell.exe”

-noexit -command "& {ADD-PSSNAPIN SQLServerCmdletSnapin100; ADD-PSSNAPIN SQLServerProviderSnapin100}"

Now believe it or not, this ACTUALLY makes sense.  No really, I’m not pulling your leg.

“-noexit” Means after you Launch the Powershell session and run the Cmdlets or commands provided in the Command parameter, keep Powershell open.  Yes “DON’T EXIT”

“-command” Means to run the following commands in Powershell.  In our case we’re going to execute the two ADD-PSSNAPIN Cmdlets to add the SQL Server Management Snapins.  The Semicolon separating them is exactly what you think it means.  “End of this line”.  It’s the demark between one Powershell CmdLet and another.   Handy if we can’t put an invisible carriage return in there.

When you see the “& “ that means to send everything to Powershell EXACTLY as you see it.  Also note, when doing this technique, the –command parameter and all it’s goodies must be the LAST thing in the line.

Click on “Apply” and try your new Shortcut.  Doesn’t seem to do anything magic?  Of course not.   That’s because this is a normal Windows Powershell console with the SQL Snapins added in and AVAILABLE to you.

How do you tell they are there?



There you go.  

So is there a point to ANY of this?  Sure there is.  Ever have to create a new User?  Is there any chance you might have a Vendor or inhouse application storing it’s OWN variant on user information in an SQL database?

Maybe not?

Take this to note.   It’s not difficult to add additional Snap-ins or modules this way.   It’s just another way of shaping Powershell to your own needs.

Remember, the Power of Shell is in YOU

The Energized Tech