join the MSSQLTips community

MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

 
Powershell Series #1: Setting up Powershell - Charley Hanania

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

Charley Hanania

Powershell Series #1: Setting up 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...

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:

get-PSSnapin 

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

ii $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...

 

Comments

No Comments

About Charley Hanania

Based in Zurich, Charley Hanania is Principle Consultant at QS2 – Quality Software Solutions. Prior to this worked for UBS as the Production Product Owner, responsible for SQL Server Production Operations within the Investment Bank. He has been focussed on SQL Server since version 4.2 on OS/2 and with over 15 years of experience in IT he has supported and consulted to numerous organisations in database training, development, architecture and administration related areas throughout Europe and Australasia. Communities are Charley's passion, and he became active in database communities in the mid 90's, participating in SQL Server and heterogeneous database user groups in Australia. He continues to lead an active role through various community events, the SwissITPro User Group and the Swiss PASS Chapter. www.sqlpass.ch/

View Charley Hanania's profile on LinkedIn