sqlps Utility
The sqlps utility starts a 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.
The sqlps utility starts the PowerShell environment (PowerShell.exe) with the SQL Server PowerShell snap-ins loaded and registered. The SQL Server PowerShell snap-ins are as follows:
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 cmdlet.
You can use sqlps 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, sqlps 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.
A. Run sqlps 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}"