Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between PowerShell / SQL Server snap in's / tools?

I'm a bit confused with PowerShell snap in's and other "tools" that interact with SQL Server. So what is the difference between these tools:

  • SMO
  • SQLPS Module
  • SQLPSX
  • SQL Server PowerShell provider
like image 897
jrara Avatar asked Feb 29 '12 14:02

jrara


People also ask

What is PowerShell SQL Server?

PowerShell is the preferred scripting tool used by Windows and Active Directory administrators. It can also be used to administer SQL Server or even just export data.

How do I connect SQL Server Management Studio to PowerShell?

A second option, right-click a node under Object Explorer, within SQL Server Management Studio (SSMS), and select “Start PowerShell”. The SQLPS utility's main access point is using the provider “SQLSERVER:\” to browse SQL Server like a file directory.

What is the name of the SQL module in PowerShell?

SQL Server provides a Windows PowerShell module called sqlps that is used to import the SQL Server components into Windows PowerShell. The sqlps module loads two Windows PowerShell modules: A SQL Server provider, which enables a simple navigation mechanism similar to file system paths.


1 Answers

SMO or SQL Server Management Objects is a set of .NET classes used by developers to create applications which manage SQL Server. Introduced in SQL Server 2005, the SMO classes have been updated on each SQL Server release to cover new management functionality. SMO is the underlying API used to build SQL Server Management Studio as well as the rest of the tools in your list.

The SQLPS module is Powershell module introduced in SQL Server 2012. Prior to the 2012 release Powershell support in SQL Server was provided by a mini-shell i.e. sqlps.exe introduced in SQL 2008 with some minor enhancements in SQL Server 2008 R2. A complete discussion of the SQL mini-shell can be found here http://sev17.com/2010/05/the-truth-about-sqlps-and-powershell-v2/. The minishell sqlps.exe still exists in SQL Server 2012 as does a module called sqlps. A discussion of SQL 2012 Powershell implementation can be found here: http://sev17.com/2011/07/denali-sqlps-first-impressions/ Note: Its also possible to build a small wrapper around sqlps cmdlets and provider to create your own module for releases prior to SQL 2012 (2008 and 2008 R2). I've created a wrapper here

SQLPSX is a CodePlex project I started working on in September 2007 prior to SQL Server having any Powershell support. The first release was published in July 2008. The SQLPSX project is mostly script-based modules which means you can read the script source code. The SQLPSX project still covers many tasks not covered in the SQLPS module implementation. We tried not to overlap functionality between sqlps an sqlpsx modules although with the 2012 release there is some overlap in SSIS and backup/restore functionality. A detailed description of the SQLPSX project can be found here http://sqlpsx.codeplex.com/

SQL Server Powershell provider -- First let's define provider. A provider allows a user to interact with data like a file system where you cd, dir, copy, remove, etc. Note: Providers don't implement all functionality for instance the SQL Provider with a few exceptions does not cover copy, new, remove.

Powershell ships with several providers including a file system provider and registry provider. You can see the providers installed on your system by running get-psprovider. SQL Server 2008 and higher (although the provider is backwards compatible) includes a SQL Server provider. The provider implements a SQL Server "drive" where you can navigate a SQL Server instance and cd into databases, tables, etc. The functionality is very similar to what you'd see in SQL Server Management Studio. One common questions people have is where you can browse the data in SQL Server table and the answer is no. The SQL Server Provider is used for managing SMO objects. You can use the cmdlet invoke-sqlcmd to run queries much like you could do in the old command-line version sqlcmd.The SQL provider is included in the sqlps minishell as well as the sqlps module.

like image 80
Chad Miller Avatar answered Oct 05 '22 23:10

Chad Miller