DBA Tooling · 2026

sqmSQLTool

Die DBA-Toolbox

87 Funktionen. Ein Modul. Vom Backup bis zum automatischen AlwaysOn-Repair.

PowerShell 5.1 dbaTools 2.x Pester-Tests 6 Domaenen 🇦🇪 DE  |  🇧🇳 EN v2.x

Uwe Janke · Senior SQL Server DBA · dtcSoftware

Windows PowerShell 5.1 — sqmSQLTool v2.x

# AlwaysOn-Repair - vollautomatisch

PS> Repair-sqmAlwaysOnDatabases -SqlInstance 'SQL01' -Auto

[OK] Finanzen - removed, reseeded, joined AG

[OK] Controlling - removed, reseeded, joined AG

 

# AG-aware Backup - nur bevorzugter Knoten

PS> Invoke-sqmUserDatabaseBackup -SqlInstance 'SQL01' -All -CheckPreferredReplica

 

# Health-Check + Security

PS> Get-sqmDatabaseHealth -SqlInstance 'SQL01' | Format-Table

PS> Invoke-sqmSaObfuscation -SqlInstance 'SQL01'

 

# Inventar - HTML-Report generieren

PS> Invoke-sqmInstanceInventory -SqlInstance 'SQL01' -OutputPath 'C:\Reports'

Report saved: C:\Reports\SQL01_Inventory_20260520.html

Motivation

The Problem

🔥

AlwaysOn-DB nicht synchron

Manueller Eingriff: Remove DB, Cleanup Secondary, Backup, Restore, Add to AG. 30-90 Minuten. Nachts um 3 Uhr.

⏱️

Backup-Job laeuft auf dem falschen Node

AG-Preferred-Replica nicht geprueft. Primary macht Backup statt Secondary. I/O-Spike im Produktivbetrieb.

🔍

Inventarisierung? Excel.

Wer hat sysadmin? Welche DBs haben kein Backup? Welche Instanz hat welchen Patch-Stand? - Manuelle Abfragen, unvollstaendig.

📋

Compliance-Nachweis fehlt

Auditoren fragen: Wann war das letzte CHECKDB? SA-Account noch aktiv? Login-Audit vorhanden? - Kein zentraler Report.

🐛

Deadlock passiert - niemand weiss wann

Extended Events manuell einrichten, Trace-Datei auswerten. Bis die Analyse fertig ist, ist das Problem vergessen.

🔧

Keine einheitlichen DBA-Prozesse

Jeder DBA hat eigene Scripts. Kein Standard, keine Nachvollziehbarkeit, keine Pester-Tests.

Business Value

The Value

87
Funktionen

Ein Modul - kein Tool-Zoo

30-90 min
AlwaysOn-Repair

automatisch statt manuell

0
manuelle Eingriffe

bei naectlichem AG-Fehler

SituationFrueherMit sqmSQLTool
AG-DB nicht synchronManuelle Reparatur 30-90 Min. Automatischer Repair-Job (stuendlich)
Backup-AuditExcel-Liste, veraltet Get-sqmDatabaseHealth - Bericht per Klick
Deadlock-AnalyseExtended Events manuell Get-sqmDeadlockReport - sofort
SA-Account aktivOft uebersehen Invoke-sqmSaObfuscation - 1 Befehl
Patch-StandAd-hoc Abfrage Invoke-sqmPatchAnalysis - alle Instanzen
✓ Alle Funktionen Pester-getestet und produktionserprobt auf SQL Server 2019/2022/2025

Ueberblick

6 Functional Domains

87 Funktionen - 6 Themengebiete. Jedes Gebiet in sich vollstaendig.

🇦🇪 DE  |  🇧🇳 EN  —  sqmSQLTool ist zweisprachig. Alle Ausgaben (Logs, Meldungen, HTML-Reports, Mail-Benachrichtigungen) erscheinen in der konfigurierten Sprache. Umschalten: Set-sqmConfig -Language 'en-US' bzw. 'de-DE'.
🔴

AlwaysOn & HA

Repair, Sync, Failover, Seeding, AG-Add/Remove, Repair-Job - vollstaendiger AG-Lebenszyklus

💾

Backup & Integritaet

Backup mit AG-Aware-Logik, Backup-Exclude-Tabelle, Integrity-Check, Restore, Ola-Jobs

📊

Health & Diagnose

Database Health, Wait Stats, Blocking, AutoGrowth, VLF-Count, Long Running Queries, Missing Indexes

🔐

Sicherheit & Compliance

SA-Obfuscation, Login-Audit, Sysadmin-Report, AD-Account-Status, SPN-Report, Zertifikate

Performance

PerfBaseline, PerfCounters, Index-Fragmentierung, Missing Indexes, Query Store, Wait Statistics

📋

Inventory & Doku

Instance Inventory, Database Documentation, Server Configuration Compare, Patch Analysis

Eye-Catcher · AlwaysOn & HA

Automatic AlwaysOn Repair

Eine AG-DB verliert die Synchronisation - das Tool erkennt es, repariert vollautomatisch, schreibt ins Windows Event Log.

1
Erkennung

Prueft SynchronizationState aller AG-Datenbanken. Nicht HEALTHY oder SYNCHRONIZED = Kandidat

2
Automatic Seeding sicherstellen

Invoke-sqmSqlAlwaysOnAutoseeding auf allen Replicas - Voraussetzung fuer AutoSeed-Repair

3
Remove aus AG

Remove-DbaAgDatabase - sauber, mit dbaTools

4
Secondary bereinigen

DB auf allen Secondaries loeschen - kein verwaister Zustand

5
Recovery-Modus pruefen

Setzt auf FULL falls abgewichen - sonst schlaegt Add fehl

6
Add mit AutoSeed

Add-DbaAgDatabase -SeedingMode Automatic - kein Backup/Restore noetig

7
Event Log + Protokoll

EventId 1000/1001/1002 in Windows Application Log. Invoke-sqmLogging fuer File-Log

# Manuell aufrufen:
Repair-sqmAlwaysOnDatabases

# Als stuendlichen Agent-Job einrichten:
New-sqmAlwaysOnRepairJob -Schedule "FREQ=HOURLY;INTERVAL=1"

# Testen ohne Aenderungen:
Repair-sqmAlwaysOnDatabases -WhatIf

# Ausgabe:
# SqlInstance  DatabaseName  AvailabilityGroup  Status
# -----------  ------------  -----------------  ------
# SQLNODE01    SalesDB       AG_PROD_01         RepairSuccess
# SQLNODE01    HRDB          AG_PROD_01         RepairSuccess
✓ New-sqmAlwaysOnRepairJob erstellt automatisch einen SQL Agent Job - stuendliche Ueberwachung ohne DBA-Eingriff

Eye-Catcher · Backup & Integritaet

AG-Aware Backup

Invoke-sqmUserDatabaseBackup kennt AlwaysOn. Prueft sys.fn_hadr_backup_is_preferred_replica() - laeuft nur auf dem richtigen Node.

⚠ Das Problem ohne dieses Feature - Backup-Job laeuft auf Primary UND Secondary. Doppelter I/O. Backup-Dateien redundant. Restore-Entscheidung unklar.
✓ Mit -CheckPreferredReplica - Job prueft ob dieser Node der bevorzugte Backup-Node ist. Wenn nicht: sofortiger Abbruch. Kein Backup. Kein I/O.
1
-UseExcludeTable

Liest master.dbo.sqm_BackupExclude - Datenbanken die bewusst ausgeschlossen sind (Sync-sqmBackupExcludeTable pflegt die Tabelle)

2
-MailTo / -MailOnSuccess

Backup-Report per SQL Database Mail - standardmaessig nur bei Fehler oder Abbruch. -MailOnSuccess fuer immer.

3
BackupPath aus Server Properties

Liest BackupDirectory automatisch aus den Server Properties. Kein hardcodierter Pfad im Job.

# Standard: alle User-DBs, AG-aware
Invoke-sqmUserDatabaseBackup -All -CheckPreferredReplica

# Mit Exclude-Tabelle und Mail-Report
Invoke-sqmUserDatabaseBackup -All `
    -CheckPreferredReplica `
    -UseExcludeTable `
    -MailTo "dba-team@firma.de"

# Als Backup-Maintenance-Job anlegen
New-sqmBackupMaintenanceJob `
    -SqlInstance "SQLNODE01" `
    -CheckPreferredReplica `
    -MailTo "dba-team@firma.de"
ℹ Backup-Pfad-Regel - Pfad muss auf 'User-Db' enden (aus Server Properties oder -BackupPath Parameter)

Deep Dive · Health & Diagnose

Database Health - One Command

Get-sqmDatabaseHealth prueft 8 Dimensionen pro Datenbank. Ergebnis: TXT-Report + CSV. Sofort verwendbar.

PruefpunktSchwellwert
Recovery ModelWarnung wenn nicht FULL
Letztes CHECKDBWarnung wenn aelter als 14 Tage (konfigurierbar)
Letztes Backup (Full)Rot wenn nie / aelter als konfiguriert
Letztes Backup (Diff/Log)Warnung wenn nicht vorhanden
AutoGrowth EventsLetzte 30 Tage (konfigurierbar)
VLF-AnzahlWarnung ab 200 (konfigurierbar)
DatenbankgroesseInfo
DB-StatusRot wenn nicht Online
ℹ Pipeline-faehig - Get-sqmDatabaseHealth -SqlInstance 'SQL01','SQL02','SQL03' prueft mehrere Instanzen in einem Aufruf
# Einzelne Instanz
Get-sqmDatabaseHealth

# Mehrere Instanzen
Get-sqmDatabaseHealth `
    -SqlInstance "SQL01","SQL02" `
    -MaxCheckDbAgeDays 7 `
    -MaxVlfCount 100 `
    -OutputPath "D:\Reports"

# Ausgabe (Auszug):
# Database   Status  LastFull    VLFs  CheckDB   AutoGrowth
# --------   ------  --------    ----  -------   ----------
# SalesDB    ok      2026-05-19  48    ok        3 Events
# HRDB       WARN    2026-05-01  312   ok        0 Events
# ArchiveDB  ERROR   never       89    14d ago   0 Events

Deep Dive · Sicherheit & Compliance

Security Hardening - Audit-Ready

Auditoren fragen konkrete Fragen. sqmSQLTool liefert konkrete Antworten - und behebt Schwachstellen automatisch.

1
SA-Obfuscation

Invoke-sqmSaObfuscation - umbenennen + zufaelliges 32-Zeichen Passwort. Voraussetzung: AD-Gruppe als sysadmin gesetzt. Rueckgabe: neuer Name + Passwort als Objekt.

2
Login-Audit

Invoke-sqmLoginAudit - alle Logins, Rollen, letzter Login-Zeitpunkt. Erkennt verwaiste, deaktivierte und inaktive Accounts. Als CSV exportierbar.

3
Sysadmin-Report

Get-sqmSysadminAccounts - sofortige Uebersicht welche Accounts sysadmin-Rechte haben. Fuer Audit-Nachweise.

Audit-FrageFunktionAufwand
SA-Account noch aktiv?Invoke-sqmSaObfuscation1 Befehl
Wer hat sysadmin?Get-sqmSysadminAccounts1 Befehl
Letzte CHECKDB?Get-sqmDatabaseHealthAutomatischer Report
Inaktive Logins?Invoke-sqmLoginAuditCSV-Export
SPNs korrekt?Get-sqmSpnReportVergleich AD vs. erwartet
Zertifikate ablaufend?Get-sqmCertificateReportWarnung bei <30 Tage
⚡ Bankenregulierung (BAIT/MaRisk) fordert regelmaessige Nachweise ueber privilegierte Accounts. Diese Funktionen liefern die Nachweise direkt.

Deep Dive · Performance

Performance Analysis - From Slow to Solution

Kein manuelles DMV-Stoebern mehr. sqmSQLTool liefert priorisierte Empfehlungen.

1
Wait Statistics - Wo wartet SQL Server?

Get-sqmWaitStatistics - Top Wait Types mit Gewichtung. Sofort sichtbar ob I/O, CPU, Locking oder Memory das Problem ist.

2
Missing Indexes - Was fehlt?

Get-sqmMissingIndexes - aus sys.dm_db_missing_index_details, priorisiert nach Impact Score. Mit CREATE INDEX Statement.

3
Long Running Queries - Was dauert?

Get-sqmLongRunningQueries - aktuelle + historische Langlaeufer aus DMVs, mit Query-Text-Auszug.

4
PerfBaseline - Ist das normal?

Invoke-sqmPerfBaseline - sammelt Performance-Counters ueber einen Zeitraum, speichert als CSV-Baseline fuer Vergleiche.

# Schritt 1: Was wartet gerade?
Get-sqmWaitStatistics | Select-Object -First 5

# WaitType          WaitMs  Percentage
# --------          ------  ----------
# PAGEIOLATCH_SH    45823   38.2 %
# LCK_M_S           12401   10.3 %
# CXPACKET           9822    8.2 %

# Schritt 2: Welche Indexes fehlen?
Get-sqmMissingIndexes -SqlInstance "SQL01" |
    Sort-Object ImpactScore -Descending |
    Select-Object -First 3

# Schritt 3: Baseline aufzeichnen (15 Min.)
Invoke-sqmPerfBaseline -Duration 15 `
    -OutputPath "D:\Baseline"

Deep Dive · Inventory & Doku

Instance Inventory - One Command, Full Picture

Invoke-sqmInstanceInventory dokumentiert eine Instanz vollstaendig: Version, DBs, Logins, Jobs, AlwaysOn. TXT + CSV automatisch.

1
Instanz-Metadaten

Version, Edition, Patch-Level, Collation, Max Memory, CPU-Anzahl, sp_configure-Werte

2
Datenbanken

Name, Status, Recovery Model, Groesse, letztes Backup, Owner, Collation - alle User-DBs

3
Logins & Rollen

Alle Logins mit Typ, Status, Serverrollen - sofort fuer Audit verwendbar

4
SQL Agent Jobs

Alle Jobs mit Status, Owner, Schedule, letzter Ausfuehrung und Ergebnis

5
AlwaysOn

AGs, Replicas, Listener, Sync-Status - nur wenn konfiguriert

✓ Pipeline-faehig - 'SQL01','SQL02','SQL03' | Invoke-sqmInstanceInventory - Fleet-Dokumentation per Mausklick
# Einzelne Instanz dokumentieren
Invoke-sqmInstanceInventory

# Mehrere Instanzen (Fleet)
'SQL01','SQL02','SQL03' |
    Invoke-sqmInstanceInventory `
    -ContinueOnError `
    -OutputPath "\\srv\DBA-Reports\Inventory"

# Patch-Stand aller Instanzen
Invoke-sqmPatchAnalysis `
    -SqlInstance 'SQL01','SQL02','SQL03'

# Ausgabe:
# Instance  Version  CU       LatestCU  Status
# --------  -------  --       --------  ------
# SQL01     2022     CU14     CU16      WARN
# SQL02     2022     CU16     CU16      ok
# SQL03     2019     RTM      CU27      ERROR

Qualitaet & Testbarkeit

Production-Grade - Pester-Tested

sqmSQLTool ist keine Skript-Sammlung. Es ist ein PS-Modul mit Unit-Tests, strukturiertem Logging und einheitlichen Konventionen.

Modul-Struktur

1
Public / Private

Klare Trennung oeffentlicher API (87 Funktionen) und interner Helpers. Invoke-sqmLogging, Invoke-sqmHelpers nur intern.

2
Pester Unit-Tests

Tests unter /tests/Unit/ fuer alle kritischen Funktionen. Mocking von dbaTools-Calls - kein echter SQL Server noetig.

3
Einheitliches Logging

Invoke-sqmLogging: File + EventLog + Verbose. Jede Funktion loggt konsistent. Zentrales OutputPath per Set-sqmConfig.

4
Install / Update

Install.cmd / Install.ps1: Auto-detect Admin, AllUsers oder CurrentUser. Robocopy ohne Zone.Identifier. Update.ps1 fuer Upgrades.

EigenschaftWert
Oeffentliche Funktionen87
Pester-Test-Dateien~15
PowerShell-Version5.1 (PS 7 kompatibel)
AbhaengigkeitendbaTools ≥ 2.0
LoggingFile + Windows EventLog
KonfigurationSet-sqmConfig / Get-sqmConfig
Install-ScopeAuto-detect Admin → AllUsers
ℹ Get-sqmConfig / Set-sqmConfig - Zentrale Konfiguration: OutputPath, CentralPath, LogLevel. Einmal setzen, alle Funktionen verwenden es.

Toolchain

sqmSQLTool in der Toolchain

sqmSQLTool ist das operative Rueckgrat. Alle anderen Tools stuetzen sich darauf.

1
SQLSetupTool
PostInstall: sqmSQLTool-Funktionen
2
AlwaysOnSetup
Endpoint, CONNECT, Monitoring
3
sqmSQLTool
Laufender Betrieb
4
DeadlockCollector
Nutzt sqmLogging
5
SSRSDeployment
Install-sqmSsrsReportServer
⚙️

SQLSetupTool → sqmSQLTool

PostInstall ruft: Invoke-sqmNtfsSetup, Invoke-sqmSaObfuscation, Invoke-sqmMonitoringKey, Install-sqmOlaMaintenanceSolution, New-sqmOlaMaintenanceJobs

🔷

AlwaysOnSetup → sqmSQLTool

Endpoint-Konfiguration, Monitoring-Key, SA-Check nach AG-Einrichtung

📦

dbaTools

Basis fuer alle SQL-Operationen. sqmSQLTool ist eine Unternehmens-Erweiterungsschicht ueber dbaTools

🪟

Windows Event Log

Repair-sqmAlwaysOnDatabases schreibt EventId 1000/1001/1002 - sichtbar im SIEM/Splunk

AlwaysOnSetup SQLSetupTool SQLMigration DeadlockCollector SSRSDeploymentTool

Abgrenzung

Scope & What's Next

AufgabesqmSQLTool?
AlwaysOn Auto-Repair✓ Ja - Repair-sqmAlwaysOnDatabases
AG-Aware Backup✓ Ja - Invoke-sqmUserDatabaseBackup
Instanz-Inventar✓ Ja - Invoke-sqmInstanceInventory
SA-Haertung✓ Ja - Invoke-sqmSaObfuscation
SQL Server installieren- Nein → SQLSetupTool
AlwaysOn einrichten- Nein → AlwaysOnSetup
Datenbanken migrieren- Nein → SQLMigration
SSRS Reports deployen- Nein → SSRSDeploymentTool
Deadlock-Sammlung GUI- Nein → DeadlockCollector

Was sqmSQLTool bewusst nicht ist

ℹ Kein Installer-Tool - sqmSQLTool konfiguriert und ueberwacht. Installation und Einrichtung uebernehmen SQLSetupTool und AlwaysOnSetup.
ℹ Kein Monitoring-System - sqmSQLTool liefert Daten und Reports. Splunk, SCOM, eigenes Monitoring konsumiert diese Daten.
✓ Erweiterbar - Neue Firmenfunktionen folgen dem sqm*-Muster. Logging, Config, Pester-Tests - Konventionen sind etabliert.

Referenz

Quick Reference - Die wichtigsten Befehle

Die Befehle die ein DBA taeglich oder woechentlich braucht.

Taeglicher Betrieb

AufgabeBefehl
AG-Health pruefenGet-sqmAgHealthReport
Blocking pruefenGet-sqmBlockingReport
Lange QueriesGet-sqmLongRunningQueries
Disk SpaceGet-sqmDiskSpaceReport
Instanz-CheckGet-sqmSQLInstanceCheck
AG RepairRepair-sqmAlwaysOnDatabases
User-DB BackupInvoke-sqmUserDatabaseBackup -All

Woechentlich / Monatlich

AufgabeBefehl
DB Health ReportGet-sqmDatabaseHealth
Patch-StandInvoke-sqmPatchAnalysis
Missing IndexesGet-sqmMissingIndexes
VLF/AutoGrowthGet-sqmAutoGrowthReport
Login-AuditInvoke-sqmLoginAudit
Sysadmin-PruefungGet-sqmSysadminAccounts
InventarisierungInvoke-sqmInstanceInventory

Zusammenfassung

Summary & Next Steps

AlwaysOn-Repair vollautomatisch

Repair-sqmAlwaysOnDatabases + New-sqmAlwaysOnRepairJob. AG-DB Fehler = Agent Job repariert automatisch

AG-Aware Backup

sys.fn_hadr_backup_is_preferred_replica geprueft. Kein Doppel-Backup mehr auf Primary und Secondary

Audit-Ready in Minuten

SA-Obfuscation, Login-Audit, Sysadmin-Report, CHECKDB-Status - alle Compliance-Fragen beantwortet

Fleet-Management

Pipeline-faehige Funktionen: Inventar, Patch-Stand, Health-Report fuer N Instanzen gleichzeitig

Unternehmens-Standard

87 Funktionen, Pester-Tests, einheitliches Logging - keine Script-Sammlung sondern ein Modul

Installation

# Von Share installieren (empfohlen)
Install.cmd            # auto-detect Admin -> AllUsers

# Manuell als Admin (AllUsers)
.\Install.ps1 -Scope AllUsers

# Manuell CurrentUser
.\Install.ps1 -Scope CurrentUser

# Konfiguration setzen
Set-sqmConfig -OutputPath "D:\DBA-Reports"

Links & Ressourcen

GitHubgithub.com/JankeUwe/sqmSQLTool
Websitewww.powershelldba.de
Modul-ImportImport-Module sqmSQLTool
SQLSetupTool - Basis-Installation AlwaysOnSetup - HA-Konfiguration SQLMigration - Datenbankmigrationen DeadlockCollector - Deadlock-Erfassung ReportDeploymentTool - SSRS Deployment