Commands / Test-sqmOlaInstallation
Maintenance

Test-sqmOlaInstallation

Checks whether Ola Hallengren's Maintenance Solution is installed on a SQL Server instance by testing for the DatabaseBackup stored procedure in master, optionally also DatabaseIntegrityCheck and IndexOptimize, plus whether the CommandLog table exists and SQL Agent is running.

Module: sqmSQLTool
Requires: dbatools
ShouldProcess: No
Output: PSCustomObject

Execution Flow

START Connect-DbaInstance → read JobServer.ServiceStatus master.sys.objects: procedure 'DatabaseBackup' exists? Found? IsInstalled = true IsInstalled = false -RequiredSet in Integrity/Index? check Database- IntegrityCheck -RequiredSet == Index? check Index- Optimize master.sys.tables: 'CommandLog' exists? missing → add Warning (LogToTable=N) Return PSCustomObject (IsInstalled, AgentRunning, ...) DONE
"CommandLog missing" is reported as a warning, not a failure — Ola's solution can run with @LogToTable = 'N', so its absence doesn't necessarily mean the maintenance jobs are broken, just that their execution history isn't being logged to a table. Pairs with Install-sqmOlaMaintenanceSolution and New-sqmOlaMaintenanceJobs.

Parameters

ParameterTypeRequiredDescription
-SqlInstanceStringOptionalSQL Server instance. Default: local computer name.
-SqlCredentialPSCredentialOptionalSQL authentication credential for the connection.
-RequiredSetStringOptionalWhich components to additionally verify: Backup (default, just DatabaseBackup), Integrity (adds DatabaseIntegrityCheck), or Index (adds IndexOptimize too).

Return Value

Returns a single PSCustomObject with: IsInstalled, AgentRunning, PresentObjects (array of found procedure names), Warnings (array), Message.

Examples

Example 1 — Check for the base backup procedures

Test-sqmOlaInstallation -SqlInstance "SQL01"

Example 2 — Require integrity check + index maintenance too

Test-sqmOlaInstallation -SqlInstance "SQL01" -RequiredSet Index

Example 3 — Gate installation on the result

$r = Test-sqmOlaInstallation -SqlInstance "SQL01"
if (-not $r.IsInstalled) { Install-sqmOlaMaintenanceSolution -SqlInstance "SQL01" }