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
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
Parameter
Type
Default
Description
-SqlInstance
String[]
$env:COMPUTERNAME
One or more SQL Server instances. Accepts pipeline input.
-SqlCredential
PSCredential
—
SQL Server credentials. Omit for Windows Authentication.
-SourcePath
String
GitHub ZIP URL
Alternative source for the ZIP archive — use a local or UNC path in environments without internet access.
-Force
Switch
$false
Reinstall even if Ola objects are already present. Alias: -Update.
-Update
Switch
$false
Alias for -Force.
-ContinueOnError
Switch
$false
Continue processing remaining instances after a failure.
-EnableException
Switch
$false
Throw exceptions immediately instead of logging them.
Return Value
Property
Description
SqlInstance
Instance name.
SourceUsed
URL or path from which the ZIP was downloaded.
ExistingOla
$true if Ola objects were detected before the install.
Action
Installed or Updated (set after successful execution).
Human-readable result including note that no jobs were created.
Examples
# Install on local instance (downloads from GitHub)Install-sqmOlaMaintenanceSolution# Install on a named instanceInstall-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