Note: For my updated version for SQL Server 2012, see my new article here.
Many of you probably do frequent SQL 2008 R2 installation. Be it in a development environment, or deployment in production environments. For years Microsoft has given people the ability to perform unattended installations of SQL. Starting with SQL 2008 R2, it is now sysprep friendly and can be included in your golden images. But that topic is for another time! Today I wanted to provide you two scripts that automate the SQL 2008 R2 installation process the old fashion way.
You can deploy SQL 2008 R2 in 5-7 minutes, depending on your hardware using this method. You will of course need to modify some variables in the script to fit your environment. The scripts assume you are deploying on Windows Server 2008 R2. They should work with minor to no modifications on legacy operating systems.
First, you need to create an INI file that contains the settings you want. In my case I called it SQL-2008R2-base.ini. That file contains the following:
-----
;SQL SERVER 2008 R2 Configuration File
;Version 1.0, 5 May 2010
;
[SQLSERVER2008]
; Specify the Instance ID for the SQL Server features you have specified. SQL Server directory structure, registry structure, and service names will reflect the instance ID of the SQL Server instance.
INSTANCEID="MSSQLSERVER"
; Specifies a Setup work flow, like INSTALL, UNINSTALL, or UPGRADE. This is a required parameter.
ACTION="Install"
; Specifies features to install, uninstall, or upgrade. The list of top-level features include SQL, AS, RS, IS, and Tools. The SQL feature will install the database engine, replication, and full-text. The Tools feature will install Management Tools, Books online, Business Intelligence Development Studio, and other shared components.
FEATURES=SQLENGINE,CONN,SSMS,ADV_SSMS
; Displays the command line parameters usage
HELP="False"
; Specifies that the detailed Setup log should be piped to the console.
INDICATEPROGRESS="False"
; Setup will not display any user interface.
QUIET="False"
; Setup will display progress only without any user interaction.
QUIETSIMPLE="True"
; Specifies that Setup should install into WOW64. This command line argument is not supported on an IA64 or a 32-bit system.
X86="False"
; Specifies the path to the installation media folder where setup.exe is located.
MEDIASOURCE="z:\"
; Detailed help for command line argument ENU has not been defined yet.
ENU="True"
; Parameter that controls the user interface behavior. Valid values are Normal for the full UI, and AutoAdvance for a simplied UI.
; UIMODE="Normal"
; Specify if errors can be reported to Microsoft to improve future SQL Server releases. Specify 1 or True to enable and 0 or False to disable this feature.
ERRORREPORTING="False"
; Specify the root installation directory for native shared components.
INSTALLSHAREDDIR="D:\Program Files\Microsoft SQL Server"
; Specify the root installation directory for the WOW64 shared components.
INSTALLSHAREDWOWDIR="D:\Program Files (x86)\Microsoft SQL Server"
; Specify the installation directory.
INSTANCEDIR="D:\Program Files\Microsoft SQL Server"
; Specify that SQL Server feature usage data can be collected and sent to Microsoft. Specify 1 or True to enable and 0 or False to disable this feature.
SQMREPORTING="False"
; Specify a default or named instance. MSSQLSERVER is the default instance for non-Express editions and SQLExpress for Express editions. This parameter is required when installing the SQL Server Database Engine (SQL), Analysis Services (AS), or Reporting Services (RS).
INSTANCENAME="MSSQLSERVER"
; Agent account name
AGTSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE"
; Auto-start service after installation.
AGTSVCSTARTUPTYPE="Automatic"
; Startup type for Integration Services.
ISSVCSTARTUPTYPE="Automatic"
; Account for Integration Services: Domain\User or system account.
ISSVCACCOUNT="NT AUTHORITY\NetworkService"
; Controls the service startup type setting after the service has been created.
ASSVCSTARTUPTYPE="Automatic"
; The collation to be used by Analysis Services.
ASCOLLATION="Latin1_General_CI_AS"
; The location for the Analysis Services data files.
ASDATADIR="Data"
; The location for the Analysis Services log files.
ASLOGDIR="Log"
; The location for the Analysis Services backup files.
ASBACKUPDIR="Backup"
; The location for the Analysis Services temporary files.
ASTEMPDIR="Temp"
; The location for the Analysis Services configuration files.
ASCONFIGDIR="Config"
; Specifies whether or not the MSOLAP provider is allowed to run in process.
ASPROVIDERMSOLAP="1"
; A port number used to connect to the SharePoint Central Administration web application.
FARMADMINPORT="0"
; Startup type for the SQL Server service.
SQLSVCSTARTUPTYPE="Automatic"
; Level to enable FILESTREAM feature at (0, 1, 2 or 3).
FILESTREAMLEVEL="0"
; Set to "1" to enable RANU for SQL Server Express.
ENABLERANU="False"
; Specifies a Windows collation or an SQL collation to use for the Database Engine.
SQLCOLLATION="SQL_Latin1_General_CP1_CI_AS"
; Account for SQL Server service: Domain\User or system account.
SQLSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE"
; Default directory for the Database Engine user databases.
SQLUSERDBDIR="K:\Microsoft SQL Server\MSSQL\Data"
; Default directory for the Database Engine user database logs.
SQLUSERDBLOGDIR="L:\Microsoft SQL Server\MSSQL\Data\Logs"
; Directory for Database Engine TempDB files.
SQLTEMPDBDIR="T:\Microsoft SQL Server\MSSQL\Data"
; Directory for the Database Engine TempDB log files.
SQLTEMPDBLOGDIR="T:\Microsoft SQL Server\MSSQL\Data\Logs"
; Provision current user as a Database Engine system administrator for SQL Server 2008 R2 Express.
ADDCURRENTUSERASSQLADMIN="False"
; Specify 0 to disable or 1 to enable the TCP/IP protocol.
TCPENABLED="1"
; Specify 0 to disable or 1 to enable the Named Pipes protocol.
NPENABLED="0"
; Startup type for Browser Service.
BROWSERSVCSTARTUPTYPE="Automatic"
; Specifies how the startup mode of the report server NT service. When
; Manual - Service startup is manual mode (default).
; Automatic - Service startup is automatic mode.
; Disabled - Service is disabled
RSSVCSTARTUPTYPE="Automatic"
; Specifies which mode report server is installed in.
; Default value: “FilesOnly”
RSINSTALLMODE="FilesOnlyMode"
; Accept SQL Server 2008 R2 license terms
IACCEPTSQLSERVERLICENSETERMS="TRUE"
------
Next, you need to use a little script which calls the SQL installer and points it to the INI file that you've created. This script needs one parameter, the name of the SQL administrator's group. Generally this group would live in AD. You should use the format domain\account as the parameter. The script also configures Windows Server 2008 R2 auditing so that SQL can inject entries into the Windows security event log. The SQL 2008 R2 installation files must be present on the Z: drive, or you will need to change the script. I save this file as SQL-2008R2-Base.cmd.
------
:: SQL 2008 R2 Installation Script:: v1.1 03 July 2010
@echo off
z:
IF "%1"=="" GOTO Error
:: Install base SQL Server 2008 Enterprise
echo Installing base SQL Server 2008 R2...
"z:\setup.exe" /CONFIGURATIONFILE=D:\sql-2008R2-Base.ini /INDICATEPROGRESS /SQLSYSADMINACCOUNTS="%1"
:: Configure Windows Server 2008/R2 auditing policy
auditpol /set /subcategory:"application generated" /success:enable /failure:enable
:: Remove left-over SQL 2008 entry from the start menu
rmdir "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft SQL Server 2008" /q /s
exit /B
:ErrorEcho Script requires DBAdmin argument in the form domain\Group
-------
To peform the unattended installation I perform the following steps:
1. Mount SQL 2008 R2 installation files to the Z drive.
2. Copy the two scripts to the root of the D: drive.
3. Open a command window and CD to the Z: drive.
4. Type "D:\SQL-2008R2-base.cmd contoso\SQL01-DBAdmin" (use your group name)
Come back in 5-10 minutes and you should get a setup result of "0". Happy SQL installs! If you want to get really crazy with the switches, check out this MSDN Aritcle for all the options.
When I tried this, it asks for the Product Key # to be entered. Is there anyway to supply this license #, or have you encountered this? Thanks! benlindelof (at) yahoo.com
ReplyDeleteWhen you run through the "legacy" SQL 2008/R2 installation towards the very end there is an option to save the resulting .INI file. I would suggest you run the regular SQL install routine, type in your product key, then watch for the screen that will let you save your .INI file. Look through the INI and see what key word it uses to store the key.
ReplyDeleteWith the release of SQL Server 2008 R2, by default the ConfigurationFile.ini is not created when installing the Express version. Check out this blog entry for a solution on how to get the installer to generate the ConfigurationFile.ini:
ReplyDeletehttp://nickstips.wordpress.com/2010/08/16/sql-sql-server-2008-express-missing-configurationfile-ini/
ahoy derek858 how things?
ReplyDeleteI'm busy trying to perform a silent install of SQL Express 2008 and you'll be glad to know I've been referred to least 3 times on other forums to your blog, so if figured your the go to guy;)
As it stands I have a custom wrapper which after installing the application then creates a BAT script along with user inputted data such as SQL Username & Password to perform a silent install of SQL Express 2008 so it can create an application specific instance of the SQL Server.
However when I run my TestSilentInstall.bat script, I get the following error in the log file; **Value cannot be null. Parameter name: path2*** See below;
Overall summary:
Final result: SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup.
Exit code (Decimal): 1269611253
Exit facility code: 940
Exit error code: 47861
Exit message: Value cannot be null. Parameter name: path2
Start time: 2011-02-04 16:02:58
End time: 2011-02-04 16:04:02
Requested action: Install
Log with failure: C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20110204_160147\Detail.txt
************************************************
Here's my TestSilentInstall.bat script
start /wait setup.exe /qs /ACTION=INSTALL /FEATURES=SQL
/IACCEPTSQLSERVERLICENSETERMS=TRUE /QUIETSIMPLE=TRUE
/SQMREPORTING=False
/SECURITYMODE="SQL"
/SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS"
/SAPWD="password123" /INSTANCENAME=Test2Silent
/SQLSVCSTARTUPTYPE=Automatic /SQLSVCACCOUNT="NT
AUTHORITY\SYSTEM" /SQLSVCPASSWORD="password123"
/FILESTREAMLEVEL=1 /TCPENABLED="0" /NPENABLED="0"
/ENABLERANU = "FALSE"
Any advice or suggestions would be great? As i am literally banging my head against the desk at the mo, thanks a mil
ahoy derek858 how things?
ReplyDeleteI'm busy trying to perform a silent install of SQL Express 2008 and you'll be glad to know I've been referred to least 3 times on other forums to your blog, so if figured your the go to guy;)
As it stands I have a custom wrapper which after installing the application then creates a BAT script along with user inputted data such as SQL Username & Password to perform a silent install of SQL Express 2008 so it can create an application specific instance of the SQL Server.
However when I run my TestSilentInstall.bat script, I get the following error in the log file; **Value cannot be null. Parameter name: path2*** See below;
Overall summary:
Final result: SQL Server installation failed. To continue, investigate the reason for the failure, correct the problem, uninstall SQL Server, and then rerun SQL Server Setup.
Exit code (Decimal): 1269611253
Exit facility code: 940
Exit error code: 47861
Exit message: Value cannot be null. Parameter name: path2
Start time: 2011-02-04 16:02:58
End time: 2011-02-04 16:04:02
Requested action: Install
Log with failure: C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20110204_160147\Detail.txt
************************************************
Here's my TestSilentInstall.bat script
start /wait setup.exe /qs /ACTION=INSTALL /FEATURES=SQL
/IACCEPTSQLSERVERLICENSETERMS=TRUE /QUIETSIMPLE=TRUE
/SQMREPORTING=False
/SECURITYMODE="SQL"
/SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS"
/SAPWD="password123" /INSTANCENAME=Test2Silent
/SQLSVCSTARTUPTYPE=Automatic /SQLSVCACCOUNT="NT
AUTHORITY\SYSTEM" /SQLSVCPASSWORD="password123"
/FILESTREAMLEVEL=1 /TCPENABLED="0" /NPENABLED="0"
/ENABLERANU = "FALSE"
Any advice or suggestions would be great? As i am literally banging my head against the desk at the mo, thanks a mil
Ruairi,
ReplyDeleteYou might want to have SQL generate a configurationfile.ini and then try your automated install using that.
To generate the .INI you need to do a little trickery with the SQL express installer. Use the following switches:
/ACTION=Install /UIMODE=Normal
On the Ready to Install page you will see the path to the configuration file it created.
Hi Derek,
ReplyDeleteThanks for your reply, tried your suggestion and it worked a treat, thanks very much. Used the configurationfile.ini that the SQL generates when doing a normal install with some minor alterations to have the customisble silent install.
Both my .INI scripts and my .BAT scripts worked well. Though I was wondering in your opinion do you think it would be alright to use these scripts as part of an embedded install for this application that I am working on?
For instance take the parameter x86="True", if an install was to be done on a 64-bit machine would this have any major complications on the smooth running of the SQL data engine?
Ruairi,
ReplyDeleteYou probably would need two .INI files and have the batch file use the proper one depending if the host is x86 or x64. But try your .INI and batch file on a x64 machine and see what happens. In a batch file you can detect the architecture with:
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (
) ELSE (
)
Hi derek,
ReplyDeleteI tried this but fails when you are trying to run the install.bat file over a network session like ssh. What else would be required to install this through something like cygwin ssh and having it execute silently (i.e. QUIET=TRUE) ? Is there some other windows 2008 R2 permissions that you have to set?
Hi Derek,
ReplyDeleteWhile searching for a problem that I am facing in unattended installation of SQL , your Blogs name is refered to at alot of places, So I think you would be the best who could guide me in my problem,
Exactly I am making a installer via installshield which has a SQL 2008 R2 prerequisite, I have made the config files throgh the command prompt as told in MSDN.
My installer is working fine ini both upgrade and fresh install, however when I actually start SQL and try to work on it , It is not accepting my windows credentials as a ADMIN, when i have specifically used
; Windows account(s) to provision as SQL Server system administrators.
SQLSYSADMINACCOUNTS="BUILTIN\Administrators"
in the command line,
However this entry is not read in my install, Request you to guide me in this problem as it is making my Installer useless.
Hi Saurabh,
ReplyDeleteTry using this line as a parameter in your config files;
ADDCURRENTUSERASSQLADMIN=True
and remove the line SQLSYSADMINACCOUNTS="BUILTIN\Administrators". I had a similiar problem building an installer myself and found that removing BUILTIN\Administrators rectified it.
Cheers
or you could try https://sqlserverfinebuild.codeplex.com
ReplyDelete