sqlps Utility
The sqlps utility starts a Windows PowerShell 2.0 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.
Important
|
|---|
|
This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use the sqlps PowerShell module instead. For more information about the sqlps module, see Import the SQLPS Module. |
The sqlps utility starts the PowerShell environment (PowerShell.exe) and loads the SQL Server PowerShell module. The module, also named sqlps, loads and registers these SQL Server PowerShell snap-ins:
-
Microsoft.SqlServer.Management.PSProvider.dll
Implements the SQL Server PowerShell provider and associated cmdlets such as Encode-SqlName and Decode-SqlName.
-
Microsoft.SqlServer.Management.PSSnapin.dll
Implements the Invoke-Sqlcmd and Invoke-PolicyEvaluation cmdlets.
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.
By default, the sqlps utility runs with the scripting execution policy set to Restricted. This prevents running any PowerShell scripts. You can use the Set-ExecutionPolicy cmdlet to enable running signed scripts, or any scripts. Only run scripts from trusted sources, and secure all input and output files by using the appropriate NTFS permissions. For more information about enabling PowerShell scripts, see Running Windows PowerShell Scripts.
The version of the sqlps utility in SQL Server 2008 and SQL Server 2008 R2 was implemented as a Windows PowerShell 1.0 mini-shell. Mini-shells have certain restrictions, such as not allowing users to load snap-ins other than those loaded by the mini-shell. These restrictions do not apply to the SQL Server 2012 version of the utility, which has been changed to use the sqlps module.
A. Run the sqlps utility in default, interactive mode without the copyright banner
sqlps -NoLogo
B. Run a SQL Server PowerShell script from the command prompt
sqlps -Command "&{.\MyFolder.MyScript.ps1}"
C. Run a SQL Server PowerShell script from the command prompt, and keep running after the script completes
sqlps -NoExit -Command "&{.\MyFolder.MyScript.ps1}"
Important