Learning PowerShell in SQL Server 2008

October 22, 2008 at 11:28 am (PowerShell, 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.

About these ads

5 Comments

  1. Rob Farley said,

    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.

  2. scarydba said,

    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?

  3. concentrateddon said,

    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.

  4. Laerte said,

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

  5. scarydba said,

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: