Afin de lancer une installation automatique et silencieuse d’une base SQL sur vos serveurs windows, vous pouvez utiliser des scripts unattended. Cet article est lié au déploiement automatiser des VMs windows. (voir l’article)

Dans notre cas, nous souhaitions pouvoir installer de façon automatiser une base SQL 2008  avec les services pack ou une base SQL 2012 avec les services pack et ce juste après l’application du sysprep.

Pour information, nous avons intégrer dans nos templates, les scripts et sources d’installation dans C:\Install-SQL.

Dans notre Sysprep, nous avons fait exécuter au premier boot un script effectuant plusieurs configuration (voir l’article) et au sein duquel nous avons posé la question à l’utilisateur s’il voulait installer une base de données ou non et si oui quelle version :

echo “r"
Write-host "######################### INSTALLER BASE DE DONNEES ##############################" -foregroundcolor "Yellow"
echo "
r”

Do {
$BDDOK = Read-Host ‘Base de données à installer ? (Répondre “y” ou “n”)’
$BDDOK = $BDDOK.ToLowerInvariant()
} While (($BDDOK -ne “y”) -and ($BDDOK -ne “n”))

If ($BDDOK -eq “y”) {
Do {
$version = Read-Host ‘2008 ou 2012 ? (Répondre “2008” ou “2012”)’
} While (($version -ne “2008”) -and ($version -ne “2012”))

Do {
$version2 = Read-Host ‘standard ou enterprise? (Répondre “s” ou “e”)’
$version2 = $version2.ToLowerInvariant()
} While (($version2 -ne “s”) -and ($version2 -ne “e”))
If ($version -eq “2008”){
Remove-Item -Recurse -Force “C:\Install-SQL\2012”
If ($version2 -eq “s”){
regedit.exe /s “C:\Install-SQL\2008\Standard\sql2008standard.reg”
}Else {
regedit.exe /s “C:\Install-SQL\2008\Enterprise\sql2008enterprise.reg”
}
}Else {
Remove-Item -Recurse -Force “C:\Install-SQL\2008”
If ($version2 -eq “s”){
regedit.exe /s “C:\Install-SQL\2012\Standard\sql2012standard.reg”
}Else {
regedit.exe /s “C:\Install-SQL\2012\Enterprise\sql2012enterprise.reg”
}
}
}Else{
Remove-Item -Recurse -Force “C:\Install-SQL”
}

 

template01

 

Selon les choix de l’utilisateur, une clé de registre est modifiée pour qu’au reboot le script d’installation de la base de données soit exécuté. Voici le contenu du .reg qui permet au prochain reboot d’exécuter le script InstallSQL2008.bat :

 

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
“SQL”=”C:\\Install-SQL\\2008\\Enterprise\\InstallSQL2008.bat”

 

Voici le script exécuté au boot :

 

Exécution du script permettant de récupérer les variables

powershell -command “& {Set-ExecutionPolicy Unrestricted}”
powershell -file “C:\Install-SQL\2008\scriptSQL.ps1”
powershell -command “& {Set-ExecutionPolicy Restricted}”
@ECHO off

Installation de la base de données via les sources avec en paramètre le fichier ini modifié

echo Installation de SQL Server 2008 R2 en cours … Ne pas fermer cette fenetre
“C:\Install-SQL\2008\Enterprise\SQL-2008-ENTERPRISE\setup.exe” /ConfigurationFile=”C:\Install-SQL\2008\ConfigurationFile2008v2.ini”

Installation des 3 services pack

echo Installation de SQL Server 2008 R2 SP1 en cours … Ne pas fermer cette fenetre
“C:\Install-SQL\2008\SP1\SQLServer2008R2SP1-KB2528583-x64-ENU.exe /allinstances /quiet”

echo Installation de SQL Server 2008 R2 SP2 en cours … Ne pas fermer cette fenetre
“C:\Install-SQL\2008\SP2\SQLServer2008R2SP2-KB2630458-x64-ENU.exe /allinstances /quiet”

echo Installation de SQL Server 2008 R2 SP3 en cours … Ne pas fermer cette fenetre
“C:\Install-SQL\2008\SP3\SQLServer2008R2SP3-KB2979597-x64-ENU.exe /allinstances /quiet”

echo Installation terminee. Merci de tester le bon fonctionnement de SQL Server

Suppression des scripts et sources d’installation

powershell -command “&{Remove-Item -Recurse -Force “C:\Install-SQL”}”

 

 template06

 

Ce script fait appel à un fichier powershell qui récupère le nom du serveur dans la variable serveur et qui demande à l’utilisateur le nom de l’instance et le mot de passe du compte sa :

 

Récupération des variables

$serveur = Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name
$instance = Read-Host “Nom de l’instance ?”
$mdpinstance = Read-Host “Mot de passe de l’instance ? (Code Appli + nom instance en minuscule)”

Modification des champs dans le fichier .ini

get-content “C:\Install-SQL\2008\ConfigurationFile2008.ini” | foreach-object {$_ -replace “NOMSERVEUR”, $serveur} | set-content “C:\Install-SQL\2008\tempconf.ini”
get-content “C:\Install-SQL\2008\tempconf.ini” | foreach-object {$_ -replace “NOMINSTANCE”, $instance} | set-content “C:\Install-SQL\2008\tempconf2.ini”
get-content “C:\Install-SQL\2008\tempconf2.ini” | foreach-object {$_ -replace “MDPINSTANCE”, $mdpinstance} | set-content “C:\Install-SQL\2008\ConfigurationFile2008v2.ini”

Suppression des fichiers temporaires

Remove-Item “C:\Install-SQL\2008\ConfigurationFile2008.ini”
Remove-Item “C:\Install-SQL\2008\tempconf.ini”
Remove-Item “C:\Install-SQL\2008\tempconf2.ini”

 

template02

 

Ce fichier PS1 va modifier dans le fichier .ini les champs NOMSERVEUR, NOMINSTANCE et MDPINSTANCE. Biensûr, vous pouvez rentrer ces valeurs en dur dans le fichier .ini avant de lancer votre script et retirer cette partie.

Vous pouvez également au lieu de copier les sources d’installation en local, spécifier dans votre script le lecteur CD et monter l’ISO sur la VM. Il y a plein de possibilités, a vous de trouver celle qui vous arrange le plus.

A la fin de l’installation, vérifiez que les services SQL sont bien démarrés et que votre instance nommée est bien configurée :

template07

Veuillez trouver ci-dessous le fichier de configuration .ini pour l’installation silencieuse de la base SQL 2008 R2 : (En rouge les champs modifié par le script) -> ConfigurationFile2008

 

;SQLSERVER2008 Configuration File
[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=”NOMINSTANCE

; 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,REPLICATION,FULLTEXT,AS,BIDS,CONN,IS,BC,SDK,BOL,SSMS,ADV_SSMS,SNAC_SDK,OCS

; 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=”True”

; Setup will display progress only without any user interaction.

QUIETSIMPLE=”False”

; Specifies that Setup should install into WOW64. This command line argument is not supported on an IA64 or a 32-bit system.

X86=”False”

; Detailed help for command line argument ENU has not been defined yet.

ENU=”True”

; 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:\Microsoft SQL Server”

; Specify the root installation directory for the WOW64 shared components.

INSTALLSHAREDWOWDIR=”D:\Microsoft SQL Server (x86)”

; Specify the installation directory.

INSTANCEDIR=”F:\SQLDATA\NOMINSTANCE

; 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=”NOMINSTANCE

; Agent account name

AGTSVCACCOUNT=”NT AUTHORITY\SYSTEM”

; Auto-start service after installation.

AGTSVCSTARTUPTYPE=”Manual”

; Startup type for Integration Services.

ISSVCSTARTUPTYPE=”Automatic”

; Account for Integration Services: Domain\User or system account.

ISSVCACCOUNT=”NT AUTHORITY\NetworkService”

; The name of the account that the Analysis Services service runs under.

ASSVCACCOUNT=”NT AUTHORITY\SYSTEM”

; 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=”F:\SQLDATA\NOMINSTANCE\MSAS10_50.NOMINSTANCE\OLAP\Data”

; The location for the Analysis Services log files.

ASLOGDIR=”F:\SQLDATA\NOMINSTANCE\MSAS10_50.NOMINSTANCE\OLAP\Log”

; The location for the Analysis Services backup files.

ASBACKUPDIR=”F:\SQLDATA\NOMINSTANCE\MSAS10_50.NOMINSTANCE\OLAP\Backup”

; The location for the Analysis Services temporary files.

ASTEMPDIR=”F:\SQLDATA\NOMINSTANCE\MSAS10_50.NOMINSTANCE\OLAP\Temp”

; The location for the Analysis Services configuration files.

ASCONFIGDIR=”F:\SQLDATA\NOMINSTANCE\MSAS10_50.NOMINSTANCE\OLAP\Config”

; Specifies whether or not the MSOLAP provider is allowed to run in process.

ASPROVIDERMSOLAP=”1″

; Specifies the list of administrator accounts that need to be provisioned.

ASSYSADMINACCOUNTS=”NOMSERVEUR\Administrator”

; 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\SYSTEM”

; Windows account(s) to provision as SQL Server system administrators.

SQLSYSADMINACCOUNTS=”NOMSERVEUR\Administrator”

; The default is Windows Authentication. Use “SQL” for Mixed Mode Authentication.

SECURITYMODE=”SQL”

; 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”

SAPWD=MDPINSTANCE

; Add description of input argument FTSVCACCOUNT

FTSVCACCOUNT=”NT AUTHORITY\LOCAL SERVICE”

RSINSTALLMODE=”FilesOnlyMode”
IACCEPTSQLSERVERLICENSETERMS=”True”
QUIET=”True”

 

Veuillez trouver ci-dessous le fichier de configuration .ini pour l’installation silencieuse de la base SQL 2012 R2 : (En rouge les champs modifié par le script) -> ConfigurationFile2012

 

;SQL Server 2012 Configuration File
[OPTIONS]

; Specifies a Setup work flow, like INSTALL, UNINSTALL, or UPGRADE. This is a required parameter.

ACTION=”Install”

; Detailed help for command line argument ENU has not been defined yet.

ENU=”True”

; Setup will not display any user interface.

QUIET=”True”

; Setup will display progress only without any user interaction.

QUIETSIMPLE=”False”

; Specify whether SQL Server Setup should discover and include product updates. The valid values are True and False or 1 and 0. By default SQL Server Setup will include updates that are found.

UpdateEnabled=”True”

; Specifies features to install, uninstall, or upgrade. The list of top-level features include SQL, AS, RS, IS, MDS, and Tools. The SQL feature will install the Database Engine, Replication, Full-Text, and Data Quality Services (DQS) server. The Tools feature will install Management Tools, Books online components, SQL Server Data Tools, and other shared components.

FEATURES=SQLENGINE,REPLICATION,FULLTEXT,AS,BIDS,CONN,IS,BC,SDK,BOL,SSMS,ADV_SSMS,DREPLAY_CTLR,DREPLAY_CLT,SNAC_SDK

; Specify the location where SQL Server Setup will obtain product updates. The valid values are “MU” to search Microsoft Update, a valid folder path, a relative path such as .\MyUpdates or a UNC share. By default SQL Server Setup will search Microsoft Update or a Windows Update service through the Window Server Update Services.

UpdateSource=”MU”

; Displays the command line parameters usage

HELP=”False”

; Specifies that the detailed Setup log should be piped to the console.

INDICATEPROGRESS=”False”

; Specifies that Setup should install into WOW64. This command line argument is not supported on an IA64 or a 32-bit system.

X86=”False”

; Specify the root installation directory for shared components. This directory remains unchanged after shared components are already installed.

INSTALLSHAREDDIR=”D:\Microsoft SQL Server”

; Specify the root installation directory for the WOW64 shared components. This directory remains unchanged after WOW64 shared components are already installed.

INSTALLSHAREDWOWDIR=”D:\Microsoft SQL Server (x86)”

; 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=”NOMINSTANCE

; Specify the Instance ID for the SQL Server features you have specified. SQL Server directory structure, registry structure, and service names will incorporate the instance ID of the SQL Server instance.

INSTANCEID=”NOMINSTANCE

; 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”

; The Windows account(s) used to grant permission to the Distributed Replay Controller service.

CTLRUSERS=”NOMSERVEUR\Administrator”

; The account used by the Distributed Replay Controller service.

CTLRSVCACCOUNT=”NT Service\SQL Server Distributed Replay Controller”

; The startup type for the Distributed Replay Controller service.

CTLRSTARTUPTYPE=”Manual”

; The account used by the Distributed Replay Client service.

CLTSVCACCOUNT=”NT Service\SQL Server Distributed Replay Client”

; The startup type for the Distributed Replay Client service.

CLTSTARTUPTYPE=”Manual”

; 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 installation directory.

INSTANCEDIR=”F:\SQLDATA\NOMINSTANCE

; Agent account name

AGTSVCACCOUNT=”NT Service\SQLAgent$NOMINSTANCE

; Auto-start service after installation.

AGTSVCSTARTUPTYPE=”Manual”

; Startup type for Integration Services.

ISSVCSTARTUPTYPE=”Automatic”

; Account for Integration Services: Domain\User or system account.

ISSVCACCOUNT=”NT Service\MsDtsServer110″

; The name of the account that the Analysis Services service runs under.

ASSVCACCOUNT=”NT Service\MSOLAP$NOMINSTANCE

; 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=”F:\SQLDATA\NOMINSTANCE\MSAS11.NOMINSTANCE\OLAP\Data”

; The location for the Analysis Services log files.

ASLOGDIR=”F:\SQLDATA\NOMINSTANCE\MSAS11.NOMINSTANCE\OLAP\Log”

; The location for the Analysis Services backup files.

ASBACKUPDIR=”F:\SQLDATA\NOMINSTANCE\MSAS11.NOMINSTANCE\OLAP\Backup”

; The location for the Analysis Services temporary files.

ASTEMPDIR=”F:\SQLDATA\NOMINSTANCE\MSAS11.NOMINSTANCE\OLAP\Temp”

; The location for the Analysis Services configuration files.

ASCONFIGDIR=”F:\SQLDATA\NOMINSTANCE\MSAS11.NOMINSTANCE\OLAP\Config”

; Specifies whether or not the MSOLAP provider is allowed to run in process.

ASPROVIDERMSOLAP=”1″

; Specifies the list of administrator accounts that need to be provisioned.

ASSYSADMINACCOUNTS=”NOMSERVEUR\Administrator”

; Specifies the server mode of the Analysis Services instance. Valid values are MULTIDIMENSIONAL and TABULAR. The default value is MULTIDIMENSIONAL.

ASSERVERMODE=”MULTIDIMENSIONAL”

; CM brick TCP communication port

COMMFABRICPORT=”0″

; How matrix will use private networks

COMMFABRICNETWORKLEVEL=”0″

; How inter brick communication will be protected

COMMFABRICENCRYPTION=”0″

; TCP port used by the CM brick

MATRIXCMBRICKCOMMPORT=”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 Service\MSSQL$NOMINSTANCE

; Windows account(s) to provision as SQL Server system administrators.

SQLSYSADMINACCOUNTS=”NOMSERVEUR\Administrator”

; The default is Windows Authentication. Use “SQL” for Mixed Mode Authentication.

SECURITYMODE=”SQL”

; Provision current user as a Database Engine system administrator for SQL Server 2012 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”

RSINSTALLMODE=”FilesOnlyMode”

SAPWD=MDPINSTANCE

; Add description of input argument FTSVCACCOUNT

FTSVCACCOUNT=”NT Service\MSSQLFDLauncher$NOMINSTANCE

IACCEPTSQLSERVERLICENSETERMS=”True”
QUIET=”True”

 

Share