Run Windows PowerShell from SQL Server Management Studio

Applies to: SQL Server

You can start Windows PowerShell sessions from Object Explorer in SQL Server Management Studio (SSMS). SSMS launches Windows PowerShell, loads the SqlServer module, and sets the path context to the associated node in the Object Explorer tree.

Note

There are two SQL Server PowerShell modules; SqlServer and SQLPS.

The SqlServer module is the current PowerShell module to use.

The SQLPS module is included with the SQL Server installation (for backward compatibility) but is no longer updated.

The SqlServer module contains updated versions of the cmdlets in SQLPS and includes new cmdlets to support the latest SQL features.

Install the SqlServer module from the PowerShell Gallery.

For more information, see SQL Server PowerShell.

When you specify running PowerShell for an object in Object Explorer, SQL Server Management Studio starts a Windows PowerShell session in which the SQL Server PowerShell snap-ins have been loaded and registered. The path for the session is preset to the location of the object you right-clicked in Object Explorer.

For example, if you right-click the AdventureWorks database object in Object Explorer and select Start PowerShell, the Windows PowerShell path is set as seen below:

SQLSERVER:\SQL\MyComputer\MyInstance\Databases\AdventureWorks2022>

Run PowerShell

Run PowerShell from SQL Server Management Studio

  1. Open Object Explorer.

  2. Navigate to the node for the object to be worked on.

  3. Right-click the object and select Start PowerShell.

Permissions

When opened from SQL Server Management Studio, PowerShell doesn't run with Administrator privileges, which may prevent some activities such as calls to WMI.

See also