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. |
| -ContinueOnError | switch | Optional | Continue with the next job on error (rarely used). |
| -Databases | string | Optional | Database filter for IndexOptimize and IntegrityCheck user. Default: 'USER_DATABASES'. |
| -JobCategory | string | Optional | Category for all three jobs. Default: 'Database Maintenance'. |
| -JobNameIndexOpt | string | Optional | Name of the IndexOptimize job (overrides module configuration). |
| -JobNameIntSysDb | string | Optional | Name of the IntegrityCheck job for system DBs (overrides module configuration). |
| -JobNameIntUserDb | string | Optional | Name of the IntegrityCheck job for user DBs (overrides module configuration). |
| -LogToTable | string | Optional | Ola internal logging to CommandLog table. Default: 'Y'. |
| -OnlyModifiedStatistics | string | Optional | Only update modified statistics. Default: 'Y'. |
| -OperatorName | string | Optional | SQL Agent operator for email notification on failure. |
| -StatisticsSample | int | Optional | Sample size for statistics update in percent. Default: 0 (SQL Server default). |
| -Update | switch | Optional | Replace existing jobs with the same name. |
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