Getting Started with SQL Server Powershell

sqlps utility starts a Windows PowerShell  session with the SQL Server PowerShell provider and cmdlets loaded and registered.

You can enter PowerShell commands or scripts that use the SQL Server PowerShell components to work with instances of SQL Server and their objects.

You can use the sqlps utility to do the following:
  • Interactively run PowerShell commands.
  • Run PowerShell script files.
  • Run SQL Server cmdlets.
  • Use the SQL Server provider paths to navigate through the hierarchy of SQL Server objects.

To start sqlps utility : -


To start sqlps utility : - http://msdn.microsoft.com/en-us/library/hh212996.aspx


Through Windows PowerShell ,we can interact with SQL Server components by importing the sqlps module into Windows PowerShell environment .

The sqlps module loads in the SQL Server PowerShell provider and cmdlets, and the SQL Server Management Object (SMO) assemblies used by the provider and cmdlets. 

Powershell Commands:

Get-Module -listAvailable

##setting execution policy
Set-ExecutionPolicy unrestricted

## Importing  the SQLPS Module with -DisableNameChecking to suppress warnings
Import-Module “sqlps” -DisableNameChecking

Get-Command –module "sqlps"

Get-PSSnapin -registered

##if not added,to add sql server snapins
Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100

##to get commands in a snapin
Get-Command -pssnapin SqlServerCmdletSnapin100
Get-Command -pssnapin SqlServerProviderSnapin100




References :

For more,detailed & accurate Informations:

sqlps utility - http://msdn.microsoft.com/en-us/library/cc280450.aspx

To Install  - Microsoft® Windows PowerShell Extensions for Microsoft® SQL Server® 2012 - http://www.microsoft.com/en-us/download/details.aspx?id=29065

To Import SQLPS module into  Windows PowerShell environment - http://msdn.microsoft.com/en-IN/library/hh231286.aspx

To load only the SMO assemblies without the provider or cmdlets - http://msdn.microsoft.com/en-us/library/hh245202.aspx

SMO object model diagram - http://msdn.microsoft.com/en-us/library/ms162209.aspx

To navigate a hierarchy of SQL Server objects using SQL Server provider - http://msdn.microsoft.com/en-us/library/cc281947.aspx

To navigate SQL Server PowerShell Paths - http://msdn.microsoft.com/en-IN/library/hh213536.aspx

Working with SQL Server PowerShell Paths - http://msdn.microsoft.com/en-IN/library/hh213689.aspx

No comments: