dbatools is a free PowerShell module with over 200 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Install-DbaMaintenanceSolution

This script will download and install the latest version of SQL Server Maintenance Solution created by Ola Hallengren.

Screenshots

dbatools - Install-DbaMaintenanceSolution

Examples

Installs Ola Hallengren’s Solution objects on RES14224 in the master database.
Backups will default to the default Backup Directory.
If the Maintenance Solution already exists, the script will be halted.

Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -CleanupTime 72

Changes the database of the step in “Job1” with the name Step1 to msdb.

Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation “Z:\SQLBackup” -CleanupTime 72

This will drop and then recreate the Ola Hallengren’s Solution objects
The cleanup script will drop and recreate:
– TABLE [dbo].[CommandLog]
– STORED PROCEDURE [dbo].[CommandExecute]
– STORED PROCEDURE [dbo].[DatabaseBackup]
– STORED PROCEDURE [dbo].[DatabaseIntegrityCheck]
– STORED PROCEDURE [dbo].[IndexOptimize]

The following SQL Agent jobs will be deleted:
– ‘Output File Cleanup’
– ‘IndexOptimize – USER_DATABASES’
– ‘sp_delete_backuphistory’
– ‘DatabaseBackup – USER_DATABASES – LOG’
– ‘DatabaseBackup – SYSTEM_DATABASES – FULL’
– ‘DatabaseBackup – USER_DATABASES – FULL’
– ‘sp_purge_jobhistory’
– ‘DatabaseIntegrityCheck – SYSTEM_DATABASES’
– ‘CommandLog Cleanup’
– ‘DatabaseIntegrityCheck – USER_DATABASES’
– ‘DatabaseBackup – USER_DATABASES – DIFF’

Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation “Z:\SQLBackup” -CleanupTime 72 -ReplaceExisting

Author

This command was created by Viorel Ciucu. You can find Viorel on his blog.

Get-Help

From PowerShell, execute Get-Help Install-DbaMaintenanceSolution -Detailed for more information on this function.

Source Code

Want to see the source code? View Install-DbaMaintenanceSolution.ps1 on GitHub
 

Related commands