A collection of production-ready SQL Server administration and automation scripts in PowerShell and T-SQL. Built for DBAs and platform engineers managing SQL Server estates, covering backup verification, security hardening, CDC, monitoring, and migration.
- Clone the repo or download individual scripts
- Each script contains full documentation in its header — prerequisites, parameters, and examples
- For PowerShell scripts:
Get-Help .\ScriptName.ps1 -Full - For T-SQL scripts: read the comment block at the top of the file
| Script | Description |
|---|---|
| Test-SqlBackupRestore.ps1 | Restores backups from Azure Blob Storage, runs DBCC CHECKDB, and logs results |
| Script | Description |
|---|---|
| Export-SqlCdcChanges.ps1 | Exports CDC change data to Azure Blob Storage as compressed JSON |
| ResolveCDCSchemaDrift.sql | Detects and resolves schema drift by recycling CDC capture instances |
| SQLServerCDCDemo.sql | End-to-end CDC tutorial: setup, querying, PII redaction, and schema drift |
| Script | Description |
|---|---|
| Get-SqlEFMigrationHistory.ps1 | Discovers EF Core migration history across multiple instances |
| Import-AccessDatabase.ps1 | Bulk-imports all tables from a Microsoft Access database into SQL Server |
| Script | Description |
|---|---|
| ConfigureDbaAlerts.sql | Configures Database Mail, DBA operator, and SQL Agent alerts (severity 17-25, I/O errors) |
| Send-FailedTaskNotification.ps1 | Sends HTML email notifications for failed or missed Task Scheduler jobs |
| Test-SqlPatchCompliance.ps1 | Checks SQL Server CU compliance and reports via table and/or email |
| Script | Description |
|---|---|
| ConfigureLoginAudit.sql | Creates a SQL Server Audit for login success/failure tracking |
| CopyUserAccess.sql | Generates T-SQL to clone one user's permissions to another |
| CreateMcpLogin.sql | Creates a least-privilege login for AI-driven DBA monitoring via MCP |
| Find-WeakSqlPasswords.ps1 | Checks SQL logins against a list of known compromised passwords |
| GetOrphanedUsers.sql | Detects orphaned database users across all databases |
| Test-CISSqlServerBenchmark.ps1 | Runs ~40 CIS SQL Server 2019 v1.4.0 benchmark checks |
| Script | Description |
|---|---|
| CalculateWorkingHours.sql | Calculates elapsed working hours between two timestamps (excludes weekends/holidays) |
Common dependencies across scripts — each script documents its own specific requirements in its header.
- PowerShell 5.1+ or PowerShell 7+
- dbatools v2.0+ — PowerShell scripts that interact with SQL Server
- Az modules (Az.Accounts, Az.Storage, Az.KeyVault) — scripts that use Azure Key Vault or Blob Storage
- SQL Server 2012+ — minimum version varies by script
Contributions are welcome via pull request.
- Each script should include comment-based help:
.SYNOPSIS,.DESCRIPTION,.PREREQUISITES,.PARAMETER,.EXAMPLE,.LICENSE - Follow the existing naming convention: verb-first PascalCase (e.g.
Test-SqlPatchCompliance.ps1,ConfigureDbaAlerts.sql) - Place scripts in the appropriate category folder
This project is licensed under the MIT License.