Welcome to ciysys blog

Installing MSSQL server with Powershell

Published on: 11th Nov 2019

Updated on: 16th Jan 2022

Explanation

When you are installing the MSSQL Express, you might find out that you missed out changing the collation, change the instance name and other standard settings while installing them.

To avoid patching the SQL server settings, it's better to use a script and all team members to follow. Here is the script that I have come up with to install the MSSQL.

$sql_setup_file = "F:\my-setupFiles\sql2012 express\SQLEXPRWT_x64_ENU.exe "
$db_dir = "F:\my_database"
$bak_dir = "F:\my_database_backup"
$sa_pwd = "1234567890"

$param = "/QUIET /IACCEPTSQLSERVERLICENSETERMS /ACTION=""install"" /FEATURES=SQL,Tools /INSTANCENAME=sqlexpress /SQLCOLLATION=SQL_Latin1_General_CP1_CI_AS /ERRORREPORTING=0 /SQLBACKUPDIR=""$bak_dir"" /SQLUSERDBDIR=""$db_dir"" /TCPENABLED=1 /INDICATEPROGRESS /SECURITYMODE=SQL /SAPWD=""$sa_pwd"""

Write-Host "Installing SQL server... please wait.."

#start the installation.           
Start-Process -FilePath $sql_setup_file -ArgumentList $param -Wait

Write-Host "SQL installation completed"

Notes: please change the $sa_pwd before running the script.

Jump to #POWERSHELL blog

Author

Lau Hon Wan, software developer.