Udostępnij za pośrednictwem


Launching Vanilla PowerShell from SSMS

One of the criticisms of our PowerShell implementation is the integration with Management Studio launches our custom minishell. With just a few simple key strokes you can add a custom tool menu item and toolbar button. To do this select "External Tools..." from the "Tools" menu in Management Studio.

ExternalToolsMenu 

The following dialog is displayed.

ExternalToolsDialog

The above picture shows the dialog filled in to launch the vanilla PowerShell shell. You could add custom arguments, such as -nologo, if you desire and you can set the default directory. You could also use this to run a specific script. The title you enter will show up in the "Tools".

CustomToolMenuItem

Once you've registered the custom tool you can add it to any toolbar. Here I'll add it to the default toolbar. Just select "Customize..." from the "Tools" menu.

CustomizeMenu 

The Customize dialog will be displayed. Unfortunately Visual Studio doesn't replace the generic "External Command 1". In this example I only have one external tool defined so I'll grab "External Command 1" and drag it to the toolbar.

CustomizeDialog

This adds a button to the toolbar to launch the custom tool. Thankfully Visual Studio replaces the generic name with the name entered into the Title field.

CustomToolbarButton

The first-class integration on the Object Explorer context menu will launch you into SQLPS.exe directly to the selected object. This integration won't do the same but if you need to shell out into vanilla PowerShell this is a quick way to do so from within SSMS. If you combine this with the registration of the SQL Server provider extensions in a vanilla PS environment you might just get close to the best of both worlds.