Learn more about SQL Server tools

mssqltips logo

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Scripts          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories


Powershell Series #1 Setting up Powershell

By:   |   Updated: 2009-07-14   |   Comments   |   Related: More > PowerShell

OK, first things first...

I have SQL Server 2008 installed locally (developer edition) on Vista, which I believe installs Powershell for you as a component... I'm using V1.0.

The easiest way to see if its installed it to use the "run" command and type powershell...

use the run command and type powershell

If its not installed, read this article How to Download Windows PowerShell 1.0.

Once that's done, you need to set up your environment.

I would encourage you to install Marc's "Tab Completion" Tool for Powershell, which does exactly what you would expect...

You may get an error as I did when running the cmd file, and what I had to do to fix this was:

  1. Run Powershell
  2. From the Powershell Prompt type: Set-ExecutionPolicy Unrestricted

Then you can run the setup cmd file again and walk through the set up steps...

Next step is to load the SQL Server libraries so that Powershell can use them...

From Powershell Prompt type:

add-PSSnapin SqlServerProviderSnapin100
add-PSSnapin SqlServerCmdletSnapin100

To see what's loaded:


Now this will be forgotten when the powershell session closes, so add those 2 lines to the default profile:


(ii instansiates an object - like typing start [program name] from cmd prompt)

If you type $PROFILE on its own, it tells the path and name of the profile file.

If the add-snapin command errors, then you may need to install the SQL Server Powershell Providers from the Feature Pack and retry.

Next step... querying your SQL Server...

Last Updated: 2009-07-14

get scripts

next tip button

About the author
MSSQLTips author Charley Hanania Charley Hanania is based in Zurich and is a Principle Consultant at QS2 Quality Software Solutions.

View all my tips
Related Resources

Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 

Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.


Learn more about SQL Server tools