Skip to content

LUM-BitHawk/SQL-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

SQL-Server

Automating SQL Server Installation via PowerShell Automating SQL Server Installation via PowerShell

Introduction Automating the installation of SQL Server using PowerShell can simplify the deployment process, particularly in environments where multiple instances are needed. This guide provides a step-by-step approach to achieve this automation.

Prerequisites Before proceeding, ensure that you have:

  • Administrative privileges on the target machine.
  • PowerShell installed (preferably PowerShell 5.1 or later).
  • The SQL Server installation media (ISO or extracted files).

Step 1: Download SQL Server Installation Media If not already available, download the SQL Server installation media from the official Microsoft website. Extract the contents if you're using an ISO file.

Step 2: Prepare a Configuration File Create a configuration file that contains the installation parameters. Save it as ConfigurationFile.ini. Below is a sample configuration for a named SQL Server instance:

[OPTIONS]
ACTION="Install"
FEATURES="SQL"
INSTANCENAME="MYINSTANCE"
SQLSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE"
SQLSYSADMINACCOUNTS="BUILTIN\Administrators"
AGTSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE"
SECURITYMODE="SQL"
SAPWD="YourStrong!Passw0rd"
TCPENABLED=1
NPENABLED=0

Modify the parameters according to your environment and requirements.

Step 3: Create the PowerShell Script Create a PowerShell script (Install-SQLServer.ps1) to automate the installation. Here’s an example script:

....powershell Define variables $SqlInstallerPath = "C:\Path\To\SQLServer2019-x64-ENU.exe" # Update with the actual path $ConfigFilePath = "C:\Path\To\ConfigurationFile.ini" # Update with the actual path

Run the SQL Server installer with the specified configuration file Start-Process -FilePath $SqlInstallerPath -ArgumentList "/CONFIGURATIONFILE=$ConfigFilePath" -Wait -NoNewWindow

Check for errors if ($LASTEXITCODE -eq 0) { Write-Host "SQL Server installation completed successfully." } else { Write-Host "SQL Server installation failed with exit code: $LASTEXITCODE" }


Step 4: Execute the PowerShell Script
Open PowerShell as Administrator and navigate to the directory where your PowerShell script is located. Execute the script:

....powershell
.\Install-SQLServer.ps1


Step 5: Verification
After the installation completes, verify that SQL Server is installed by checking the services or trying to connect using SQL Server Management Studio (SSMS).

Conclusion
By following these steps, you can automate the installation of SQL Server using PowerShell. This method is especially useful for large-scale deployments and helps maintain consistency across installations. Customize the configuration file as needed for different environments or features.

About

Automatically install SQL Server via PowerShell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published