Learning PowerShell in SQL Server 2008

This blog post is pretty interesting.

http://concentratedtech.com/content/index.php/2008/06/sql-server-2008-powershell-no-no-no-no-no/

 

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.

5 thoughts on “Learning PowerShell in SQL Server 2008

  • scarydba

    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?

  • concentrateddon

    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.

  • scarydba

    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.

Please let me know what you think about this article or any questions:

This site uses Akismet to reduce spam. Learn how your comment data is processed.