How I use dbatools to automate SQL Server installs

I lot of you have asked me to expand on the automated SQL Server installation I mentioned in my previous article:

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

The dbatools team have spent long hours making sure everything is super simple and almost a one-liner therefore there is not that much I had to do.

First, check if SQL Server is already installed:

$SqlInstance = Find-DbaInstance -ComputerName localhost

Set the path to the install files:

Set-DbatoolsConfig -Name Path.SQLServerSetup -Value '\vmware-hostShared FoldersSQL Server ISO'

And run the installation:

if ($SqlInstance -eq $null) {
   //ASK which version of SQL to install:
   [string]$Version = Read-Host -Prompt 'Install SQL Server Version (2008R2, 2012, 2014, 2016, 2019)'

   //Get SA credentials:
   $sacredential = Get-Credential
   //Install SQL Server:
   Install-DbaInstance -Version $Version -AuthenticationMode Mixed -Feature Engine,IntegrationServices -SaCredential $sacredential -Restart -DataPath "S:SQLDATA" -LogPath "L:SQLLOGS" -TempPath "T:TEMPDB" -BackupPath "R:SQLBACKUPS" -PerformVolumeMaintenanceTasks -Confirm:$false

The script will run on startup and if SQL Server is not found, it will install it. The whole process takes less than a couple of minutes.

You can learn more about the command here :

Thanks for reading!

This post was originally published on June 8, 2020.

5 1 vote
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x