SQL Server Unattended Installation with PowerShell / No More Human Errors #IaC
a PowerShell automation script for SQL Server Installation
Hi everyone! In this article, I’ll show you “how to automate SQL Server installation with PowerShell”.
Before the script, I would like to mention infrastructure as code (#IaC) approach.
As a DBA, I set up and manage lots of servers (our team responsible 1000+ database server) That means, “welcome to the complexity and human errors world” :)
Human errors are lead to lots of problems in IT systems. We can prevent human errors with automation.
Why infrastructure as code? #IaC
- No human errors
- Easy change management
- Scalability
- Easy to use for any employee
- No wasting time
- Versioning
Now, I would like to share my SQL Server installation script. I generally use PowerShell for automation tasks. I think Powershell is one of Microsoft’s best products. Simple, flexible, powerful, supports cross-platform.
This script provides installing a SQL engine service, cumulative update and management studio to a local or remote server.
You can download the script from my GitHub page.
https://github.com/ahmetrende/PowerShell/blob/master/Install-SqlServer.ps1
There are some requirements:
- PowerShell 5.1 or above
- dbatools module (https://dbatools.io)
- CredSSP authentication
- Standard folder structure*
- Active Directory environment
#The folder structure should be like this:<YourSetupFolderPath>
-VersionNumber
-Iso files
-Cumulative update setup files
-Tools
-SSMS setup files.#My folder structure for SQL Server 2019
C:\sql\2019\SqlServer2019.ISO
C:\sql\2019\SQLServer2019-KB4548597-x64.exe
C:\sql\Tools\SSMS-Setup-ENU.exe
Here is an example of usage:
The next step is SQL Server auto-configuration with PowerShell. I’ll write an article soon.
Our team also supports to dbatools development.
Thanks for reading.
Ahmet Rende