Execution Flow
Requires Ola Hallengren's maintenance solution objects to already be installed (checked via
Test-sqmOlaInstallation -RequiredSet Index). Job names are resolved from Get-sqmConfig (OlaJobNameIndexOpt, OlaJobNameIntUserDb, OlaJobNameIntSysDb). OverallStatus can be PartialSuccess if one of the three jobs fails while others succeed.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Target SQL instance. Default: $env:COMPUTERNAME. |
| -SqlCredential | PSCredential | Optional | SQL authentication credential. |
| -FragmentationLevel1 | Int | Optional | Reorganize threshold (%). Default: 5. |
| -FragmentationLevel2 | Int | Optional | Rebuild threshold (%). Default: 30. |
| -MinNumberOfPages | Int | Optional | Minimum index size considered. Default: 1000. |
| -FillFactor | Int | Optional | Rebuild fill factor. Default: 90. |
| -MaxDOP | Int | Optional | Max degree of parallelism. Default: 0 (server default). |
| -SortInTempdb | String | Optional | Y/N. Default: Y. |
| -UpdateStatistics | String | Optional | ALL / COLUMNS / INDEX. Default: ALL. |
| -CheckCommands | String | Optional | Ola CheckCommands. Default: CHECKDB. |
| -PhysicalOnly | String | Optional | Y/N. Default: N. |
| -NoIndex | String | Optional | Y/N. Default: N. |
| -ScheduleTime | String | Optional | Default: 23:00. |
| -ScheduleDay | Int | Optional | SQL Agent weekday bitmask. Default: 1 (Sunday). |
| -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, JobNameIndexOpt, JobNameIntUserDb, JobNameIntSysDb, IndexOptStatus, IntUserDbStatus, IntSysDbStatus, OverallStatus (PartialSuccess / WhatIf / Success / Failed), Message.
Examples
Example 1 — Create all three jobs with defaults
New-sqmOlaMaintenanceJobs -SqlInstance "SQL01"
Example 2 — Custom fragmentation thresholds
New-sqmOlaMaintenanceJobs -SqlInstance "SQL01" -FragmentationLevel1 10 -FragmentationLevel2 40 -MaxDOP 4