Execution Flow
Requires Ola Hallengren's DatabaseBackup stored procedure to already exist on the instance. The script loads version-detection logic from a hardcoded module path (
jobs\SqlVersionDetection.ps1) to adjust the backup compression/verify options for the detected SQL Server version.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Target SQL instance. Default: $env:COMPUTERNAME. |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -BackupDirectory | String | Optional | Backup root path. Auto-detected from registry if omitted. |
| -JobName | String | Optional | Default from config (OlaJobNameSysDbBackup) or OlaHH-SystemDatabases-FULL. |
| -JobCategory | String | Optional | Default: Database Maintenance. |
| -ScheduleTime | String | Optional | Default: 21:15. |
| -CleanupTime | Int | Optional | Hours to retain backup files. Default: 48. |
| -Compress | String | Optional | Y/N. Default: Y. |
| -Verify | String | Optional | Y/N. Default: Y. |
| -CheckSum | String | Optional | Y/N. Default: Y. |
| -LogToTable | String | Optional | Y/N. Default: Y. |
| -OperatorName | String | Optional | SQL Agent operator for notifications. |
| -Update | Switch | Optional | Updates an existing job instead of failing. |
| -ContinueOnError | Switch | Optional | Continues on a single-database backup error. |
| -EnableException | Switch | Optional | Throws terminating errors instead of returning an error status object. |
| -WhatIf / -Confirm | Switch | Optional | Standard ShouldProcess support. |
Return Value
Returns a PSCustomObject with: SqlInstance, JobName, BackupDirectory, ScheduleTime, JobStatus, OverallStatus, Message.
Examples
Example 1 — Create with auto-detected backup path
New-sqmOlaSysDbBackupJob -SqlInstance "SQL01"
Example 2 — Explicit path and retention
New-sqmOlaSysDbBackupJob -SqlInstance "SQL01" -BackupDirectory "E:\Backup" -CleanupTime 72