Install-sqmOlaMaintenanceSolution Performance

Downloads Ola Hallengren's SQL Server Maintenance Solution from GitHub, extracts and executes the five SQL scripts in the required order (CommandExecute, CommandLog, DatabaseBackup, DatabaseIntegrityCheck, IndexOptimize). Creates only database objects — SQL Agent jobs are created separately with New-sqmOlaMaintenanceJobs. Supports -Force / -Update to reinstall over an existing installation.

Execution Flow

START dbatools available? throw; return Yes ↓ foreach $instance in $SqlInstance Test-sqmOlaInstallation -RequiredSet Backup AlreadyInstalled; continue Not installed (or -Force) ↓ Invoke-WebRequest $SourcePath → $zipFile (TEMP dir) Expand-Archive → find 'sql-server-maintenance-solution-*' subdirectory ShouldProcess (Install / Update)? Status=WhatIf foreach $scriptFile in [CommandExecute, CommandLog, DatabaseBackup, DatabaseIntegrityCheck, IndexOptimize] Test-Path $scriptPath → skip + WARNING if not found Invoke-DbaQuery -Database master -File $scriptPath -EnableException Action: 'Installed' (new) or 'Updated' (-Force over existing) finally: Remove-Item $tempDir -Recurse -Force (always cleans up ZIP + extracted files) Return List<PSCustomObject> [ SqlInstance, Status, Action, ExistingOla, Message ] DONE

Synopsis

Supports pipeline input for -SqlInstance to process multiple instances. In begin, the dbatools module is validated and the ordered list of five SQL script names is defined. For each instance, Test-sqmOlaInstallation -RequiredSet Backup checks whether the objects already exist: if yes and -Force/-Update is not set, the instance is skipped with Status=AlreadyInstalled. Otherwise the ZIP is downloaded to a unique temp directory and extracted. The five scripts are run sequentially via Invoke-DbaQuery against master. A finally block always removes the temp directory. No SQL Agent jobs are created — use New-sqmOlaMaintenanceJobs for that step.

Requires dbatools. The default -SourcePath is the official GitHub ZIP URL. Supply a local or network path as -SourcePath to avoid internet access in restricted environments.
-Force and -Update are aliases of each other. Both overwrite an existing installation by re-running all five scripts. Existing stored procedures and tables are replaced.

Syntax

Install-sqmOlaMaintenanceSolution
    [-SqlInstance <String[]>]       # default: $env:COMPUTERNAME; pipeline
    [-SqlCredential <PSCredential>]
    [-SourcePath <String>]          # default: GitHub ZIP URL
    [-Force]                         # reinstall even if already installed
    [-Update]                        # alias for -Force
    [-ContinueOnError]
    [-EnableException]
    [-WhatIf] [-Confirm]

Parameters

ParameterTypeDefaultDescription
-SqlInstanceString[]$env:COMPUTERNAMEOne or more SQL Server instances. Accepts pipeline input.
-SqlCredentialPSCredentialSQL Server credentials. Omit for Windows Authentication.
-SourcePathStringGitHub ZIP URLAlternative source for the ZIP archive — use a local or UNC path in environments without internet access.
-ForceSwitch$falseReinstall even if Ola objects are already present. Alias: -Update.
-UpdateSwitch$falseAlias for -Force.
-ContinueOnErrorSwitch$falseContinue processing remaining instances after a failure.
-EnableExceptionSwitch$falseThrow exceptions immediately instead of logging them.

Return Value

PropertyDescription
SqlInstanceInstance name.
SourceUsedURL or path from which the ZIP was downloaded.
ExistingOla$true if Ola objects were detected before the install.
ActionInstalled or Updated (set after successful execution).
StatusSuccess — installed; AlreadyInstalled — skipped; WhatIf — dry-run; Failed — error.
MessageHuman-readable result including note that no jobs were created.

Examples

# Install on local instance (downloads from GitHub)
Install-sqmOlaMaintenanceSolution

# Install on a named instance
Install-sqmOlaMaintenanceSolution -SqlInstance "SQL01\PROD"

# Force reinstall (update existing objects)
Install-sqmOlaMaintenanceSolution -SqlInstance "SQL01" -Force

# Install from internal network share (no internet required)
Install-sqmOlaMaintenanceSolution -SqlInstance "SQL01" `
    -SourcePath "\\srv\Install\OlaHallengren\sql-server-maintenance-solution.zip"

# Pipeline: install on multiple instances, continue on error
"SQL01", "SQL02", "SQL03" | Install-sqmOlaMaintenanceSolution -ContinueOnError

# Check result
$r = Install-sqmOlaMaintenanceSolution -SqlInstance "SQL01"
$r | Format-Table SqlInstance, Status, Action, ExistingOla