Oct 22 2008

Learning PowerShell in SQL Server 2008

This blog post is pretty interesting.



SQL Server 2008 comes with sqlps.exe, which is what this guy is ranting about.


To get around it, you can do this. Open the regular powershell command prompt. Run this:


notepad $profile


This opens up the profile used by PowerShell under your login. Now you can add these lines and save the file:


add-pssnapin SqlServerProviderSnapin100

add-pssnapin SqlServerCmdletSnapin100


You should now be able to run SQL Server commands through the regular PowerShell prompt. Depending on how you configure and run Powershell, you may also have to add those lines to scripts you create.


I may not have this quite right. I’m still learning. Here’s a suggestion that I should be updating the console file? He’s solving the same issue though.


More as I learn more.


  • By Rob Farley, October 22, 2008 @ 5:15 pm

    Well, if you don’t want to be typing those add-pssnapin commands every time you want to hook into SQL using powershell, then putting them into a console file can help.

  • By scarydba, October 23, 2008 @ 7:13 am

    That’s where I’m confused. I put them into the profile file and now I’m not typing them in any more. What’s the difference between placing them in the console and profile locations?

  • By concentrateddon, November 7, 2008 @ 7:39 pm

    Actually, the point is that there’s no way to make SQL Server’s own tools, including SQL Server Agent, launch anything other than the mini-shell, which doesn’t support any span-ins except the SQL ones. PowerShell’s architect (Jeffrey Snover) later said that the concept was his suggestion, and that it may not have been the best possible solution, in the end.

  • By Laerte, November 27, 2008 @ 7:57 am

    Hi…i can use the cmdlet add-pssanpin and all “snapin” cmdlets related ins SQLPS.exe…why ?…how can i do to use ?

  • By scarydba, November 28, 2008 @ 10:10 am

    If I understand the question, you can add the SQL Server snapins to a regular shell. It’s the mini-shell used by the SQL Server tools that allows a very limited sub-set of snapins.

    I’m still learning this stuff, so I wouldn’t rely completely on what I’m saying here.

Other Links to this Post

RSS feed for comments on this post. TrackBack URI

Leave a comment