PowerShell transaction support for SqlServer schema changes
29K reputation · 20 May 2025, 20:27 UTC
Goal: Use PowerShell’s built‑in transaction cmdlets to automatically roll back database schema changes when an error occurs during a script.
Constraint: The SqlServer provider does not implement ITransactionSupport, so Start-Transaction does not enlist Invoke-Sqlcmd statements; any SQL executed outside an explicit SqlTransaction is committed immediately and is not undone by Undo-Transaction.
Uncertainty: Whether PowerShell should extend its transaction infrastructure to the SqlServer provider, or whether users must rely on manual ADO.NET transactions or custom error handling for safe rollback.
Questions: Should PowerShell provide a configuration switch or provider update that enables automatic enlistment of SqlServer commands in a PowerShell transaction? What permission or scoping boundaries would need to be defined to prevent unintended side effects? How would nested transactions behave if the SqlServer provider participated in the PowerShell transaction hierarchy?