microsoft / microsoft/vscode-mssql

[Feature Request]: PowerShell Cell Support in SQL Notebooks with MSSQL Connection Context and SMO Integration

Open
#22,692 0 comments 0 reactions 0 assignees View on GitHub
Area - SQL Notebook Enhancement User-filed
Dominant language
TypeScript
Stars
1.9k
Forks
610
Avg merge
2d 3h
Merged PRs (30d)
97

Description

### Feature Description

Add support for **PowerShell cells within MSSQL SQL Notebooks** in Visual Studio Code.

PowerShell cells should integrate with the MSSQL notebook context so that PowerShell code can access the SQL Server connection associated with the notebook without requiring the user to manually create and authenticate a second connection.

Ideally, when a PowerShell cell is executed, the MSSQL extension would:

* Make the appropriate SQL Server PowerShell libraries available, such as the `SqlServer` PowerShell module.
* Load the required SQL Server Management Objects (SMO) assemblies.
* Expose the notebook's current SQL Server connection context to PowerShell.
* Provide convenient PowerShell variables or objects representing the connected SQL Server instance and current database.
* Reuse the authentication/connection context already established by the MSSQL extension where technically possible.

For example, a notebook could contain a SQL cell:

```sql
SELECT @@SERVERNAME AS ServerName,
DB_NAME() AS DatabaseName;
```

followed by a PowerShell cell operating against the same server:

```powershell
$SqlServer.Databases |
Select-Object Name, RecoveryModel, CompatibilityLevel
```

The exact implementation and object names could vary, but useful objects might include:

```powershell
$SqlServer
$SqlDatabase
$SqlConnection
```

where `$SqlServer` could expose an SMO `Server` object and `$SqlDatabase` could represent the database selected in the notebook's MSSQL connection context.

Another possible implementation would be mixed-language notebook directives such as:

```text
#!sql
```

and:

```text
#!powershell
```

The primary requirement is the ability to combine T-SQL, PowerShell, Markdown, and their respective results within the same MSSQL notebook while sharing the MSSQL connection context.

## Related Area

**Other**

This primarily relates to **SQL Notebooks / MSSQL Notebook kernel**, although it also intersects with:

* Query editor
* Connection management

### Problem and Motivation

## Problem and Motivation

Azure Data Studio notebooks supported PowerShell notebook scenarios that were particularly useful for SQL Server administration, automation, troubleshooting, and discovery.

The new MSSQL SQL Notebook experience in Visual Studio Code provides an excellent interactive environment for T-SQL and Markdown, but losing PowerShell integration creates a significant gap for DBA and SQL platform administration workflows.

PowerShell and SMO complement T-SQL because many SQL Server administrative and discovery tasks are easier to perform through the SQL Server object model than through individual T-SQL queries.

Supporting PowerShell cells with access to the notebook's existing connection context would enable notebooks to become reusable SQL Server administration and troubleshooting runbooks.

Examples include:

* SQL Server instance and database inventory
* Database configuration discovery
* SQL Server Agent job inspection
* Backup and restore administration
* Security and permissions analysis
* Availability Group and HA/DR discovery
* SQL Server configuration auditing
* SQL Assessment API execution
* Database file and storage analysis
* SMO scripting of SQL Server objects
* Azure SQL administration
* Environment discovery and documentation
* Troubleshooting runbooks combining T-SQL and PowerShell
* Administrative reports combining SQL queries, PowerShell object inspection, Markdown documentation, and results

A particularly important aspect of this feature would be **connection-context reuse**.

Without this integration, users can potentially invoke PowerShell separately, but they must reconstruct the server name, database, authentication method, credentials/tokens, and connection properties. This creates unnecessary friction and can introduce security and authentication problems.

Instead, the MSSQL notebook could provide PowerShell with a safe representation of its existing connection context.

This would allow a workflow such as:

```text
MSSQL Notebook
|
+-- Connection: SQLPROD01 / AdventureWorks
|
+-- Markdown
| Explain diagnostic procedure
|
+-- SQL Cell
| Query DMVs
|
+-- PowerShell Cell
| Inspect server/database through SMO
|
+-- SQL Cell
| Perform additional diagnostics
|
+-- PowerShell Cell
Generate administrative output
```

This would go beyond simply restoring PowerShell notebook functionality from Azure Data Studio. It would create a SQL Server-specific **administration notebook experience** where SQL, PowerShell, SMO, documentation, and the MSSQL connection manager work together.

It would be especially valuable as users migrate SQL Server administration and development workflows from Azure Data Studio to Visual Studio Code.

### Related Area

- [ ] Connection dialog (SQL Server | Azure browse/Fabric browse)
- [ ] Query editor
- [ ] Query results panel
- [ ] Object Explorer
- [ ] GitHub Copilot integration
- [ ] Preview/Edit data
- [ ] Table Designer
- [ ] Schema Designer
- [ ] Schema Compare
- [ ] Local SQL Server Container provisioning
- [ ] SQL database in Fabric provisioning
- [ ] DACPAC/BACPAC export/import
- [ ] SQL Database projects
- [ ] Query Plan Visualizer
- [ ] Other (please describe below)

### If you selected "Other", please describe the area

_No response_

### Confirmation

- [x] I have searched existing feature requests and couldn't find a match
- [ ] I want to help implement this feature

Contributor guide

No contributing guide indexed for this repository

Research direction

No implementation files, tests, or entry points are identified. Start by reviewing the MSSQL SQL Notebook/kernel and connection-management areas, then determine how SQL, PowerShell, Markdown, and shared connection context should work together. Done would include an agreed implementation design and working mixed-language notebook support with connection reuse.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, sql, vscode
Domain
database, devtools, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.