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.
Rob Farley said,
October 22, 2008 at 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.
scarydba said,
October 23, 2008 at 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?
concentrateddon said,
November 7, 2008 at 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.
Laerte said,
November 27, 2008 at 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 ?
scarydba said,
November 28, 2008 at 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.