Monday, 1 December 2014

Automating Standalone SQL Installation







Few days back I started working on Automating or Standardizing SQL Installation. Ultimate goal is to reduce the manual work. Unattended installation using configuration file will help us to achieve this. 



First let's see how to get our configuration file. First time you have to run the setup manually and pass all the parameters.  You have move till “Ready to install” page in the installation wizard. There you will get the configurationfile.ini location.





Copy the configurationfile.ini to the location where SQL setup file is placed (It’s not mandatory to do this. If you place the configuration file in different location, same location should be passed while executing the setup).


So now your configuration file is ready. Make the below changes in configuration file to perform unattended installation.

   -Change QUIET="False" to QUIET="True"
 
   -Remove UIMODE="Normal" from configurationfile.ini


Now save and close the file. Please note, configuration file will not store/have password details of any of the accounts (SQL Service Account, SQL Agent Account and SA Password etc.). So we have to pass this information explicitly while running setup in command line. And also we should pass a parameter /IACCEPTSQLSERVERLICENSETERMS=”True” to accept the SQL Software license.


Below is the script to do unattended installation.
***********************************************************************************
setup.exe /ConfigurationFile=ConfigurationFile.ini /IACCEPTSQLSERVERLICENSETERMS=”True” /SAPWD=”SaAccountPassword” /SQLSVCPASSWORD=”SQLServiceAccountPassword” /AGTSVCPASSWORD=”AgentAccountPassword”
***********************************************************************************

Note: SA password is not required for Windows Authentication


You can create a batch file and run it to perform unattended SQL installation. This will be advantageous if you have to in setup SQL in multiple servers with same configuration.



But what if you have a requirement to install SQL in multiple server with different instance name and collation settings?

Above script will not work in that case. However if you could go and make required changes to the configuration file every time will work. But again that will be time consuming task to make changes in all servers. Other option would be passing the parameters explicitly while running the setup. So here also lot of editing will be required.

To overcome all these difficulties, I wrote a small dynamic script where we have to define few parameters based on our requirement and those parameters will be taken as input while running the setup.

I have just added below parameters in my script to be taken as input.
      -SQL Instance Name
       -SQL Collation
       -SQL Service Account Name and Password
       -SQL Agent Account Name and Password
       -SA Account password
       - To accept SQL Server License Terms


Assuming in most of the case install directory, root instance directory and other directory will be standard. So initially whatever you have passed in the configuration file will be taken.

You may need to change the below script according to your requirement.
***********************************************************************************
@echo off
color 02
echo===========================================
echo Unattended SQL Installation
echo===========================================
color 05
set /p LI=Do You Accept SQL Server License Terms(True/False):
set /p IN=Enter SQL Instance Name:
set /p SYS=Enter Sysadmin Account Name:
set /p SA=Enter SA Account Password:
set /p SVN=Enter SQL Service Account Name:
set /p SVP=Enter SQL Service Account Password:
set /p AGN=Enter SLQ Agent Account Name:
set /p AGP=Enter SQL Agent Account Password:
set /p COL=Enter SQL Collation:
color 09
echo===========================================
Echo Starting SQL Server Installation....
echo===========================================
date/t
time/t
setup.exe /ConfigurationFile=ConfigurationFile.ini /IACCEPTSQLSERVERLICENSETERMS=%LI% /INSTANCENAME=%IN% /INSTANCEID=%IN% /SQLSYSADMINACCOUNTS=%SYS% /SQLCOLLATION=%COL% /SAPWD=%SA% /SQLSVCACCOUNT=%SVN% /SQLSVCPASSWORD=%SVP% /AGTSVCACCOUNT=%AGN% /AGTSVCPASSWORD=%AGP%
color 02
echo Batch file completed
date /t
time /t

***********************************************************************************
Now all you have to do is prepare your configuration file and save the above script in .bat format. Place both the files where SQL Setup is placed.
That’s it, open command prompt with “Run as administrator”, run the batch file, provide required inputs and your SQL installation will start. 

Below is the screenshot of SQL installation in my system.
 


You will get the start and end time of installation. To make it bit sparkling added few colors in between the code.  So on each phase of batch execution you would notice a change in color!!!
To learn more about Unattended SQL Installation click here.

Hope this helps in Automating SQL Installation :-)

Cheers,
Naveen


2 comments:

  1. Naveen,
    Great post! was really very helpful.
    Just one doubt, how can we incorporate feature selection also in this automation process?

    ReplyDelete
    Replies
    1. Kevin,
      Glad that it helped.
      Simple way is you can install all features and then disable the services which are not required.
      Else you have to add "/FEATURES" parameters explicitly and provide necessary inputs.

      Delete

Please share your thoughts