Execution Flow
Default
ScheduleDays depends on -BackupType: FULL → Sunday, DIFF → Mon–Sat, LOG → every day. The Always On propagation step recursively calls itself against each secondary replica unless -SkipAlwaysOnPropagation is set.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Target SQL instance. Default: $env:COMPUTERNAME. |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -JobName | String | Optional | Agent job name. Default: sqm-BackupMaintenance-FULL. |
| -BackupType | String | Optional | FULL / DIFF / LOG. Default: FULL. |
| -BackupPath | String | Optional | Target backup directory. |
| -ScheduleTime | String | Optional | Daily start time. Default: 20:00. |
| -ScheduleDays | String[] | Optional | Days the job runs. Default depends on -BackupType. |
| -ScheduleIntervalMinutes | Int | Optional | Recurrence interval (0–1440), used mainly for LOG backups. |
| -JobCategory | String | Optional | Agent job category. Default: Database Maintenance. |
| -UseExcludeTable | Switch | Optional | Excludes databases listed in sqm_BackupExclude at runtime. |
| -CheckPreferredReplica | Switch | Optional | Aborts the backup on a non-preferred AG replica. |
| -IncludeSystemDatabases | Switch | Optional | Includes system databases in the backup scope. |
| -MailTo | String | Optional | Recipient for Database Mail notifications. |
| -MailProfile | String | Optional | Database Mail profile name. Default: Default. |
| -MailOnSuccess | Switch | Optional | Sends mail on success as well as failure. |
| -OperatorName | String | Optional | SQL Agent operator for job notifications. |
| -Update | Switch | Optional | Updates an existing job instead of failing. |
| -SkipAlwaysOnPropagation | Switch | Optional | Skips recursive job creation on AG secondary replicas. |
| -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, BackupType, Step1Command, Step2Command, ScheduleName, ScheduleDays, ScheduleTime, Status, Message.
Examples
Example 1 — Standard FULL backup job
New-sqmBackupMaintenanceJob -SqlInstance "SQL01" -BackupType "FULL" -BackupPath "E:\Backup"
Example 2 — LOG backup job with exclude table and mail
New-sqmBackupMaintenanceJob -SqlInstance "SQL01" -BackupType "LOG" -UseExcludeTable -MailTo "dba@firma.de"