Execution Flow
Standard defaults:
-Full Sunday 20:00, -Diff Mon–Sat 20:00, -Log every day, every 15 minutes. When -UseExcludeTable is combined with auto-detection, an existing FULL/LOG job's schedule (if present) is reused, otherwise the default 21:15 daily FULL / 15-min LOG cadence is applied and the DIFF job is auto-disabled. Secondary-replica propagation reuses this same function recursively, tagging results Secondary_<status>.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Target SQL instance. Default: $env:COMPUTERNAME. |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -Full / -Diff / -Log | Switch | At least one required | Which backup type job(s) to create. |
| -BackupDirectory | String | Optional | Backup root path; target is <path>\Usr-db. |
| -UseExcludeTable | Switch | Optional | Reads sqm_BackupExclude at job runtime via dynamic SQL, and triggers schedule auto-detection from existing jobs. |
| -JobCategory | String | Optional | Default: Database Maintenance. |
| -EnableException | Switch | Optional | Throws terminating errors instead of returning an error status object. |
| -SkipAlwaysOnPropagation | Switch | Optional | Skips recursive job creation on AG secondary replicas. |
| -WhatIf / -Confirm | Switch | Optional | Standard ShouldProcess support. |
| -CheckSum | string | Optional | Checksum calculation. Default: 'Y'. |
| -CleanupTime | int | Optional | Age in hours after which backup files are deleted. Default: 48. 0 = no cleanup. |
| -Compress | string | Optional | Backup compression. Default: 'Y'. |
| -ContinueOnError | switch | Optional | Continue with remaining jobs if one job fails. |
| -CreateSyncJob | bool | Optional | When -UseExcludeTable is set, automatically creates a SQL Agent job that runs Sync-sqmBackupExcludeTable every 30 minutes via pwsh CmdExec step. Ensures IsActive changes (made via Show-sqmBackupExcludeForm) are propagated to all AG secondaries without manual intervention. Default: $true. Set to $false to suppress job creation. |
| -Databases | string | Optional | Database filter for Ola. E.g. 'USER_DATABASES', 'ALL_DATABASES', or comma-separated DB names like 'DB1,DB2'. Default: 'USER_DATABASES'. |
| -Diff | switch | Optional | Creates a DIFF backup job. |
| -DiffJobName | string | Optional | Overrides the job name for DIFF read from the configuration. |
| -DiffScheduleDays | string[] | Optional | Days of the week for the DIFF job. Default: @('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'). |
| -DiffScheduleIntervalMinutes | int | Optional | Repeat interval for the DIFF job in minutes. 0 = once. Default: 0. |
| -DiffScheduleTime | string | Optional | Start time of the DIFF job in format 'HH:mm'. Default: '20:00'. |
| -FullJobName | string | Optional | Overrides the job name for FULL read from the configuration. |
| -FullScheduleDays | string[] | Optional | Days of the week for the FULL job as an array. Valid values: 'Monday'..'Sunday', 'Weekdays', 'Weekend', 'EveryDay'. Multiple days: @('Monday','Wednesday','Friday'). Default: @('Sunday'). |
| -FullScheduleIntervalMinutes | int | Optional | Repeat interval for the FULL job in minutes (e.g. 60 = hourly). 0 = no interval, job runs once at FullScheduleTime. Default: 0. |
| -FullScheduleTime | string | Optional | Start time of the FULL job in format 'HH:mm'. Default: '20:00'. |
| -Log | switch | Optional | Creates a LOG backup job. |
| -LogJobName | string | Optional | Overrides the job name for LOG read from the configuration. |
| -LogScheduleDays | string[] | Optional | Days of the week for the LOG job. Default: @('EveryDay'). |
| -LogScheduleIntervalMinutes | int | Optional | Repeat interval for the LOG job in minutes (e.g. 15 = every 15 minutes). 0 = once at LogScheduleTime. Default: 0. |
| -LogScheduleTime | string | Optional | Start time of the LOG job in format 'HH:mm'. Default: '00:00'. |
| -LogToTable | string | Optional | Ola internal logging to CommandLog table. Default: 'Y'. |
| -OperatorName | string | Optional | SQL Agent operator for email notification on failure. |
| -Update | switch | Optional | Replace existing jobs with the same name. |
| -Verify | string | Optional | Backup verification. Default: 'Y'. |
Return Value
Returns an array of PSCustomObject, one per created backup type, each with: SqlInstance, BackupType, JobName, BackupDirectory, Databases, ScheduleTime, ScheduleDays, JobStatus, OverallStatus, Message.
Examples
Example 1, Create FULL + LOG jobs with exclude table
New-sqmOlaUsrDbBackupJob -SqlInstance "SQL01" -Full -Log -UseExcludeTableExample 2, All three types, explicit backup path
New-sqmOlaUsrDbBackupJob -SqlInstance "SQL01" -Full -Diff -Log -BackupDirectory "E:\Backup"