Question Installation SQL Server 2008R2
- SiSMik
- Auteur du sujet
- Hors Ligne
- Membre platinium
-
Réduire
Plus d'informations
- Messages : 492
- Remerciements reçus 0
il y a 11 ans 7 mois #11529
par SiSMik
Réponse de SiSMik sur le sujet Re:Installation SQL Server 2008R2
Laurent Dardenne écrit:
Tout à fait, prend la version Advanced Express comme ça tu auras les outils Management Studio et de par la même occasion les modules powershell qui vont bien.
Il faudra juste que tu vires les comptes pour SSIS et SSAS ainsi que les services associés dans les différents tableaux du script.
J'ai une version pour 2008R2 Express au boulot, je te posterais ça demain<br><br>Message édité par: benduru, à: 17/04/12 00:07
De mon côté, et dans un premier temps, je recherche une installation automatique du produit que j'aimerais couplé à une génération de base réalisé sour PowerAMC.
As-ton avis ce script peut-il être utilisé avec une version 2008 R2 express ?
Tout à fait, prend la version Advanced Express comme ça tu auras les outils Management Studio et de par la même occasion les modules powershell qui vont bien.
Il faudra juste que tu vires les comptes pour SSIS et SSAS ainsi que les services associés dans les différents tableaux du script.
J'ai une version pour 2008R2 Express au boulot, je te posterais ça demain<br><br>Message édité par: benduru, à: 17/04/12 00:07
Connexion ou Créer un compte pour participer à la conversation.
- SiSMik
- Auteur du sujet
- Hors Ligne
- Membre platinium
-
Réduire
Plus d'informations
- Messages : 492
- Remerciements reçus 0
il y a 11 ans 7 mois #11530
par SiSMik
Réponse de SiSMik sur le sujet Re:Installation SQL Server 2008R2
Voilà le script qu'on utilise pour la version 2008R2 Express with advanced Services.
[code:1]
param([string]$managed,[string]$AdminPassword,[string]$UserAccount,[string]$UserPassword,[string]$DBName)
#############################
# #
# Main variables definition #
# #
#############################
$logfile = \"C:\log\SQL2K8R2InstallAdvancedExpress.log\" # Log file
if ($hostname.length -gt 15)
{
$computer = $hostname
} else {
$computer = $env:computername
}
# Directories
$sourcesdir = \"C:\Temp\SQL\EXP\sources\\" # This is the directory where SQL Server install binaries are stored
$scriptdir = \"C:\Temp\SQL\EXP\scripts\\" # This is the directory where the script Powsershell, sc.exe & ntrights.exe are located.
$data_disk = \"D:\\"
# SQL Instance
$instanceName = \"MSSQLSERVER\" # The name you want the instance have
# The password for services account
$SVC_Pwd = \"zAqw2008!\"
# HKLM path where TCP/IP port is stored
$HKML_IPall = \"HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll\"
# SQL Requests
$QueryMaxMemory = \"EXEC sp_configure 'show advanced options', '1'
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'min server memory', '0'
EXEC sp_configure 'max server memory', ' + CAST(@Memory AS nvarchar) + '
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'show advanced options', '0'
RECONFIGURE WITH OVERRIDE\"
$QueryMaxMeroySetted = \"select value FROM sys.configurations where Name = 'max server memory (MB«»)'\"
$TempDBadd = \"USE [master]
GO
DECLARE @cpu_count int,
@file_count int,
@logical_name sysname,
@file_name nvarchar(520),
@physical_name nvarchar(520),
@size int,
@max_size int,
@growth int,
@alter_command nvarchar(max)
SELECT @physical_name = physical_name,
@size = size / 128,
@max_size = max_size / 128,
@growth = growth / 128
FROM tempdb.sys.database_files
WHERE name = 'tempdev'
SELECT @file_count = COUNT(*)
FROM tempdb.sys.database_files
WHERE type_desc = 'ROWS'
SELECT @cpu_count = cpu_count
FROM sys.dm_os_sys_info
WHILE @file_count < @cpu_count -- Add * 0.25 here to add 1 file for every 4 cpus, * .5 for every 2 etc.
BEGIN
SELECT @logical_name = 'tempdev' + CAST(@file_count AS nvarchar)
SELECT @file_name = REPLACE(@physical_name, 'tempdb.mdf', @logical_name + '.ndf')
SELECT @alter_command = 'ALTER DATABASE [tempdb] ADD FILE ( NAME =N''' + @logical_name + ''', FILENAME =N''' + @file_name + ''', SIZE = ' + CAST(@size AS nvarchar) + 'MB, MAXSIZE = ' + CAST(@max_size AS nvarchar) + 'MB, FILEGROWTH = ' + CAST(@growth AS nvarchar) + 'MB )'
PRINT @alter_command
EXEC sp_executesql @alter_command
SELECT @file_count = @file_count + 1
END\"
$TempDBmodify = \"ALTER DATABASE tempdb MODIFY FILE ( NAME = N'tempdev', SIZE = 256MB, MAXSIZE = 512MB, FILEGROWTH = 64MB )\"
$TempLogDBmodify = \"ALTER DATABASE tempdb MODIFY FILE ( NAME = N'templog', SIZE = 256MB, MAXSIZE = 512MB, FILEGROWTH = 64MB )\"
$SelectTempDB = \"SELECT max_size FROM tempdb.sys.database_files WHERE name = 'tempdev'\"
$SelectTempLogDB = \"SELECT max_size FROM tempdb.sys.database_files WHERE name = 'templog'\"
$CountTempDBFiles = \"SELECT COUNT(*) as numcpu FROM tempdb.sys.database_files where type_desc = 'ROWS'\"
$CpuCount = \"SELECT cpu_count FROM sys.dm_os_sys_info\"
#############################
# #
# Main functions definition #
# #
#############################
# This function write on the ouput is $silent is not activated
# Three level of log are recorded, INFO, ERROR, WARNING.
Function Write-Log {
param([int] $level=0,
[string] $message=$null)
$timestamp = Get-Date -format \"yyyyMMdd_HH:mm:«»ss\"
switch($level) {
0 {Write-Output \"$timestamp : INFO : $message\" }
1 {Write-Output \"$timestamp : WARNING : $message\" }
2 {Write-Output \"$timestamp : ERROR : $message\" }
}
}
# This function Write an error on Host.
function GetError {
param ([string]$text = $null,
[int]$ExitNb = $null)
Write-Host \"$text FAILED: ERROR $ExitNb\"
Exit $ExitNb
}
# This function inform on the ouput
Function Create-LogInfo {
param([string] $Libelle =$null,
[string] $Status =$null)
$currentDate = date -Format \"dd/MM/yyyy - HH:mm:«»ss - \"
if ($libelle.length -lt \"7\"«»)
{
\"$currentDate $Libelle\" + \"`t`t: $Status\" >> $logfile
}
else
{
\"$currentDate $Libelle\" + \"`t: $Status\" >> $logfile
}
if ($error) {
$error >> $logfile
$error.clear()
}
}
# This function create an array for paths
function Add-Path {
param([string]$Path,[string]$label)
$d = New-Object PSObject
$d | Add-Member -Name Path -MemberType NoteProperty -Value $Path
$d | Add-Member -Name Label -MemberType NoteProperty -Value $label
return $d
}
# This function create an array for Rights
function Add-Rights {
param([string]$wmi,[string]$name)
$d = New-Object PSObject
$d | Add-Member -Name wmi -MemberType NoteProperty -Value $wmi
$d | Add-Member -Name name -MemberType NoteProperty -Value $name
return $d
}
# This function create an array for account
function Add-Account {
param([string]$account,[string]$label,[string]$desc)
$d = New-Object PSObject
$d | Add-Member -Name account -MemberType NoteProperty -Value $account
$d | Add-Member -Name desc -MemberType NoteProperty -Value $desc
return $d
}
# function create an array for Services
function Add-Service {
param([string]$name,[string]$shortname,[string]$desc,[string]$startup)
$d = New-Object PSObject
$d | Add-Member -Name name -MemberType NoteProperty -Value $name
$d | Add-Member -Name shortname -MemberType NoteProperty -Value $shortname
$d | Add-Member -Name desc -MemberType NoteProperty -Value $desc
$d | Add-Member -Name startup -MemberType NoteProperty -Value $startup
return $d
}
# Create User function
Function Create-LocalUser {
param([string]$user,[string]$password,[string]$desc)
$objOu = [ADSI]\"WinNT://localhost\"
$objUser = $objOU.Create(\"User\", $user)
#$objGrp = [ADSI](\"WinNT://localhost/Administrators\"«»)
$objUser.setpassword($password)
$objUser.SetInfo()
$objUser.description = \"$desc\"
$objUser.SetInfo()
#$objGroup.PSBase.Invoke(\"Add\",$objUser.PSBase.Path)
}
# Account array
$listofaccounts = @()
$listofaccounts += Add-Account -account \"svc_sqls_fcp\" -label \"\" -desc \"Service account for SQL Server\"
$listofaccounts += Add-Account -account \"svc_sqlb_fcp\" -label \"\" -desc \"Service account for SQL Server Browser\"
$listofaccounts += Add-Account -account \"svc_sqlrs_fcp\" -label \"\" -desc \"Service account for SQL Server Reporting Service\"
$listofaccounts += Add-Account -account \"svc_sqlft_fcp\" -label \"\" -desc \"Service account for SQL Server Full Text Search\"
# SQL Paths // Warning if you change Path here do not forget to change them in $CreateDB var.... !!!!!
$ListOfPaths = @()
$ListOfPaths += Add-Path -path \"D:\system_db\" -label \"System Files\"
$ListOfPaths += Add-Path -path \"D:\system_db_x86\" -label \"Shared System Files\"
$ListOfPaths += Add-Path -path \"D:\backup_db\" -label \"Backup directory\"
$ListOfPaths += Add-Path -path \"D:\config_db\" -label \"Config Directory\"
$ListOfPaths += Add-Path -path \"D:\user_db\" -label \"Data for SQL Server instance\"
$ListOfPaths += Add-Path -path \"D:\log_db\" -label \"Log for SQL Server instance\"
$ListOfPaths += Add-Path -path \"D:\temp_db\" -label \"Temp database for SQL Server instance\"
$ListOfPaths += Add-Path -path \"D:\temp_log_db\" -label \"Log of TempDB for SQL Server instance\"
# Local policies
$localrights = @()
$localrights += Add-Rights -wmi \"SeTcbPrivilege\" -name \"Act as part of the operating system\"
$localrights += Add-Rights -wmi \"SeIncreaseQuotaPrivilege\" -name \"Adjust memory quotas for a process\"
$localrights += Add-Rights -wmi \"SeCreateTokenPrivilege\" -name \"Create a token object\"
$localrights += Add-Rights -wmi \"SeImpersonatePrivilege\" -name \"Impersonate a client after authentication\"
$localrights += Add-Rights -wmi \"SeBatchLogonRight\" -name \"Log on as a batch job\"
$localrights += Add-Rights -wmi \"SeServiceLogonRight\" -name \"Log on as a service\"
$localrights += Add-Rights -wmi \"SeAssignPrimaryTokenPrivilege\" -name \"Replace a process level token\"
$localrights += Add-Rights -wmi \"SeManageVolumeNamePrivilege\" -name \"Perform volume maintenance tasks\"
$localrights += Add-Rights -wmi \"SeLockMemoryPrivilege\" -name \"Lock pages in memory\"
$localrights += Add-Rights -wmi \"SeChangeNotifyPrivilege\" -name \"Bypass traverse checking\"
# This function set privileges for account services
function Set-SePrivilege {
param ([string]$path=$null)
$setup = ($scriptdir+\"ntrights.exe\"«»)
foreach ($acc in $listofaccounts)
{
[string]$account = $acc.account
[string]$desc = $acc.desc
Create-LogInfo \"Set Privileges for $desc\" \"START\"
foreach ($right in $localrights) {
[string]$wmi = $right.wmi
[string]$desc = $right.name
$i = $setup + \" +r $wmi -u $account\"
Invoke-Expression $i
Create-LogInfo \"Give $desc right for $account\" \"SUCCESS\"
}
if ( $account -match \"svc_sqls_\" ) {
net localgroup Administrators $account /ADD
Create-LogInfo \"Modify ACLs\" \"START\"
$set_Right = cscript ($scriptdir+\"xcacls.vbs\"«») $data_disk /E /G $env:computername\`\"$account`\":F /SPEC B
if ($set_right) {
Create-LogInfo \"Give Full control on $data_disk for $account\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Give Full control on $data_disk for $account\"; GetError \"Error Giving Full control on $data_disk for $account\" $errorcode
}
}
}
}
$ServicesList = @()
$ServicesList += Add-Service -name \"SQL Server (MSSQLSERVER)\" -shortname \"MSSQLSERVER\" -desc \"Provides storage, processing and controlled access of data, and rapid transaction processing.\" -startup \"Automatic\"
$ServicesList += Add-Service -name \"SQL Server Browser\" -shortname \"SQLBrowser\" -desc \"Provides SQL Server connection information to client computers.\" -startup \"Automatic\"
$ServicesList += Add-Service -name \"SQL Server Reporting Services (MSSQLSERVER)\" -shortname \"ReportServer\" -desc \"Manages, executes, renders, schedules and delivers reports.\" -startup \"Automatic\"
$ServicesList += Add-Service -name \"SQL Full-text Filter Daemon Launcher (MSSQLSERVER)\" -shortname \"MSSQLFDLauncher\" -desc \"Service to launch full-text filter daemon process which will perform document filtering and word breaking for SQL Server full-text search. Disabling this service will make full-text search features of SQL Server unavailable.\" -startup \"Automatic\"
#########################################
#########################################
# #
# Do not edit anything after this point #
# #
#########################################
# clean previous Errors
if ($error) { $error.clear() }
$errorcode = 300
# Create log dir
if (!(Test-Path \"C:\log\\"«»)) {
New-Item -path \"C:\log\" -itemType \"Directory\"
}
# Create Directories
Create-LogInfo \"Create Folders\" \"START\"
Foreach ($dir in $ListOfPaths) {
[string]$name = $dir.label
if (New-Item -path $dir.path -itemType \"Directory\" -force) {
Create-LogInfo \"Create Folder for $name\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Create Folder for $name\" \"ERROR\"; GetError \"Can't create folder for $name\" $errorcode
}
}
# Add Firewall features and ports
Create-LogInfo \"Configure Firewall\" \"START\"
if ((netsh firewall set opmode enable) -and (netsh firewall add portopening TCP 1433 \"SQLServer($instanceName)\" enable subnet) -and (netsh firewall add portopening UDP 1434 \"SQLBrowser($instanceName)\" enable subnet) -and (netsh firewall set service fileandprint enable)) {
Create-LogInfo \"Configure Firewall\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configure Firewall\" \"ERROR\"; GetError \"Error Configuring Firewall\" $errorcode
}
# Add users
create-LogInfo \"Create accounts\" \"START\"
foreach ($account in $listofaccounts) {
[string]$a = $account.account
[string]$b = $account.desc
if (Create-LocalUser -user $account.account -password $SVC_Pwd -desc $account.desc) {
$errorcode++
Create-LogInfo \"Create $b\" \"SUCCESS\"
$acc = Get-WmiObject Win32_UserAccount -computername \".\" -filter \"LocalAccount=True AND` Name='$a'\"
$acc.PasswordChangeable=$false
$acc.PasswordExpires=$false
if ($acc.put()) {
$errorcode++
Create-LogInfo \"Modify $b\" \"SUCCESS\"
} else {
Create-LogInfo \"Modify $b\" \"ERROR\"; GetError \"Error modify the $b\" $errorcode
}
} else {
Create-LogInfo \"Create $b\" \"ERROR\"; GetError \"The account $b is not created\" $errorcode
}
}
$GetSVC = gwmi Win32_UserAccount -computername \".\" -filter \"LocalAccount=True\" | ?{ $_.name -match \"svc_\" }
if ($GetSVC.length -eq $listofaccounts.count) {
Create-LogInfo \"Create accounts\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Create accounts\" \"ERROR\"; GetError \"All accounts not created\" $errorcode
}
# Give correct privileges
Create-LogInfo \"Set Privileges\" \"START\"
if (Set-SePrivilege $scriptdir) {
Create-LogInfo \"Set Privileges\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Set Privileges\" \"ERROR\"; GetError \"Error Seting Privileges\" $errorcode
}
###########################
# #
# SQL Server installation #
# #
###########################
Create-LogInfo \"SQL Installation\" \"START\"
$inv = $sourcesdir + \"setup.exe /SAPWD=\" + $AdminPassword + \" /CONFIGURATIONFILE=\" + $scriptdir + \"config.ini\"
invoke-expression $inv
if (ps | ?{$_.name -eq \"sqlservr\"})
{
Create-LogInfo \"Install SQL\" \"SUCCESS\"
$errorcode++
}
else
{
Create-LogInfo \"Install SQL\" \"ERROR\"; GetError \"Install SQL\" $errorcode
}
############################
# #
# SQL Server Configuration #
# #
############################
# Network configuration
Create-LogInfo \"TCP/IP Configuration\" \"START\"
$HKML_IPall = \"HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll\"
Set-ItemProperty $HKML_IPall -name \"TcpPort\" -value \"1433\"
Set-ItemProperty $HKML_IPall -name \"TcpDynamicPorts\" -value \"\"
$Get_TcpPort = (Get-ItemProperty $HKML_IPall).TcpPort
$Get_TcpDynamicPorts = (Get-ItemProperty $HKML_IPall).TcpDynamicPorts
if (($Get_TcpPort -eq 1433) -and ($Get_TcpDynamicPorts -eq \"\"«»)) {
Create-LogInfo \"Configuring TCP Port\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configuring TCP Port\" \"ERROR\"; GetError \"Error Configuring TCP Port\" $errorcode
}
# Load SQL CMDLETS
add-pssnapin sqlserverprovidersnapin100
add-pssnapin sqlservercmdletsnapin100
# Configuration of TempDB
Create-LogInfo \"Configure TempDB File\" \"START\"
Invoke-Sqlcmd -Query $TempDBmodify -Serverinstance .
$tempdbmaxsize = Invoke-Sqlcmd -Query $SelectTempDB -Serverinstance .
if ($tempdbmaxsize.max_size -eq 65536)
{
Create-LogInfo \"Configure TempDB File\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configure TempDB File\" \"ERROR\"; GetError \"Error Configure TempDB File\" $errorcode
}
Create-LogInfo \"Configure TempDB Log File\" \"START\"
Invoke-Sqlcmd -Query $TempLogDBmodify -Serverinstance .
$templogdbmaxsize = Invoke-Sqlcmd -Query $SelectTempLogDB -Serverinstance .
if ($templogdbmaxsize.max_size -eq 65536)
{
Create-LogInfo \"Configure TempDB Log File\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configure TempDB Log File\" \"ERROR\"; GetError \"Error Configure TempDB Log File\" $errorcode
}
Create-LogInfo \"Auto-Configure TempDB\" \"START\"
Invoke-Sqlcmd -Query $TempDBadd -Serverinstance .
$NumberTempDBFiles = Invoke-Sqlcmd -Query $CountTempDBFiles -Serverinstance .
$NumberCPU = Invoke-Sqlcmd -Query $CpuCount -Serverinstance .
if ($NumberTempDBFiles.numcpu -eq $NumberCPU.cpu_count)
{
Create-LogInfo \"Auto-Configure TempDB\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Auto-Configure TempDB\" \"ERROR\"; GetError \"Error Auto-Configure TempDB\" $errorcode
}
# Configure accounts for SQL Server Services
Create-LogInfo \"Configure SQL Services\" \"START\"
$i = 0
Foreach ($service in $ServicesList) {
$account = $listofaccounts[$i].account
[string]$servname = $service.shortname
$exec = C:\Temp\SQL\EXP\scripts\sc.exe config $servname obj= .\$account password= $SVC_Pwd
$i++
if ($exec -match \"SUCCESS\"«») {
Create-LogInfo \"Configure SQL Service ($servname) \" \"SUCCESS\"
$errorcode++
Stop-Service -name $servname -force
Start-Service -name $servname
$FullService = Get-Service -Name $servname
if ($FullService.Status -eq \"Running\"«»){
Create-LogInfo \"Restart SQL Service ($servname) \" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Restart SQL Service ($servname)\" \"ERROR\"; GetError \"Error Restart SQL Service ($servname)\" $errorcode
}
} else {
Create-LogInfo \"Configure SQL Service ($servname)\" \"ERROR\"; GetError \"Error Configure SQL Service ($servname)\" $errorcode
}
}
Create-LogInfo \"Configure SQL Services\" \"SUCCESS\"
exit 0[/code:1]
Et le fichier de réponse pour l'installation:
[code:1];SQLSERVER2008 Configuration File
[SQLSERVER2008]
; Instance Name
INSTANCEID=\"MSSQLSERVER\"
INSTANCENAME=\"MSSQLSERVER\"
; Silent Install
ACTION=\"Install\"
FEATURES=SQLENGINE,REPLICATION,FULLTEXT,RS,BIDS,SSMS,SNAC_SDK,OCS,SSMS,ADV_SSMS
INDICATEPROGRESS=\"False\"
QUIET=\"True\"
QUIETSIMPLE=\"False\"
; Options
HELP=\"False\"
X86=\"False\"
ENU=\"True\"
ERRORREPORTING=\"False\"
SQMREPORTING=\"False\"
SQLCOLLATION=\"French_CI_AS\"
FARMADMINPORT=\"0\"
FILESTREAMLEVEL=\"0\"
ENABLERANU=\"False\"
TCPENABLED=\"1\"
NPENABLED=\"0\"
RSINSTALLMODE=\"DefaultNativeMode\"
IAcceptSQLServerLicenseTerms
; Directories
INSTALLSHAREDDIR=\"D:\system_db\"
INSTALLSHAREDWOWDIR=\"D:\system_db_x86\"
INSTANCEDIR=\"D:\system_db\"
SQLBACKUPDIR=\"D:\backup_db\"
SQLUSERDBDIR=\"D:\user_db\"
SQLUSERDBLOGDIR=\"D:\log_db\"
SQLTEMPDBDIR=\"D:\temp_db\"
SQLTEMPDBLOGDIR=\"D:\temp_log_db\"
; Accounts service
AGTSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
ISSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
SQLSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
RSSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
FTSVCACCOUNT=\"NT AUTHORITY\LOCAL SERVICE\"
; Service configuration
AGTSVCSTARTUPTYPE=\"Automatic\"
ISSVCSTARTUPTYPE=\"Automatic\"
SQLSVCSTARTUPTYPE=\"Automatic\"
BROWSERSVCSTARTUPTYPE=\"Automatic\"
RSSVCSTARTUPTYPE=\"Automatic\"
; Security
SQLSYSADMINACCOUNTS=\"Administrator\"
SECURITYMODE=\"SQL\"
[/code:1]<br><br>Message édité par: benduru, à: 17/04/12 09:56
[code:1]
param([string]$managed,[string]$AdminPassword,[string]$UserAccount,[string]$UserPassword,[string]$DBName)
#############################
# #
# Main variables definition #
# #
#############################
$logfile = \"C:\log\SQL2K8R2InstallAdvancedExpress.log\" # Log file
if ($hostname.length -gt 15)
{
$computer = $hostname
} else {
$computer = $env:computername
}
# Directories
$sourcesdir = \"C:\Temp\SQL\EXP\sources\\" # This is the directory where SQL Server install binaries are stored
$scriptdir = \"C:\Temp\SQL\EXP\scripts\\" # This is the directory where the script Powsershell, sc.exe & ntrights.exe are located.
$data_disk = \"D:\\"
# SQL Instance
$instanceName = \"MSSQLSERVER\" # The name you want the instance have
# The password for services account
$SVC_Pwd = \"zAqw2008!\"
# HKLM path where TCP/IP port is stored
$HKML_IPall = \"HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll\"
# SQL Requests
$QueryMaxMemory = \"EXEC sp_configure 'show advanced options', '1'
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'min server memory', '0'
EXEC sp_configure 'max server memory', ' + CAST(@Memory AS nvarchar) + '
RECONFIGURE WITH OVERRIDE
EXEC sp_configure 'show advanced options', '0'
RECONFIGURE WITH OVERRIDE\"
$QueryMaxMeroySetted = \"select value FROM sys.configurations where Name = 'max server memory (MB«»)'\"
$TempDBadd = \"USE [master]
GO
DECLARE @cpu_count int,
@file_count int,
@logical_name sysname,
@file_name nvarchar(520),
@physical_name nvarchar(520),
@size int,
@max_size int,
@growth int,
@alter_command nvarchar(max)
SELECT @physical_name = physical_name,
@size = size / 128,
@max_size = max_size / 128,
@growth = growth / 128
FROM tempdb.sys.database_files
WHERE name = 'tempdev'
SELECT @file_count = COUNT(*)
FROM tempdb.sys.database_files
WHERE type_desc = 'ROWS'
SELECT @cpu_count = cpu_count
FROM sys.dm_os_sys_info
WHILE @file_count < @cpu_count -- Add * 0.25 here to add 1 file for every 4 cpus, * .5 for every 2 etc.
BEGIN
SELECT @logical_name = 'tempdev' + CAST(@file_count AS nvarchar)
SELECT @file_name = REPLACE(@physical_name, 'tempdb.mdf', @logical_name + '.ndf')
SELECT @alter_command = 'ALTER DATABASE [tempdb] ADD FILE ( NAME =N''' + @logical_name + ''', FILENAME =N''' + @file_name + ''', SIZE = ' + CAST(@size AS nvarchar) + 'MB, MAXSIZE = ' + CAST(@max_size AS nvarchar) + 'MB, FILEGROWTH = ' + CAST(@growth AS nvarchar) + 'MB )'
PRINT @alter_command
EXEC sp_executesql @alter_command
SELECT @file_count = @file_count + 1
END\"
$TempDBmodify = \"ALTER DATABASE tempdb MODIFY FILE ( NAME = N'tempdev', SIZE = 256MB, MAXSIZE = 512MB, FILEGROWTH = 64MB )\"
$TempLogDBmodify = \"ALTER DATABASE tempdb MODIFY FILE ( NAME = N'templog', SIZE = 256MB, MAXSIZE = 512MB, FILEGROWTH = 64MB )\"
$SelectTempDB = \"SELECT max_size FROM tempdb.sys.database_files WHERE name = 'tempdev'\"
$SelectTempLogDB = \"SELECT max_size FROM tempdb.sys.database_files WHERE name = 'templog'\"
$CountTempDBFiles = \"SELECT COUNT(*) as numcpu FROM tempdb.sys.database_files where type_desc = 'ROWS'\"
$CpuCount = \"SELECT cpu_count FROM sys.dm_os_sys_info\"
#############################
# #
# Main functions definition #
# #
#############################
# This function write on the ouput is $silent is not activated
# Three level of log are recorded, INFO, ERROR, WARNING.
Function Write-Log {
param([int] $level=0,
[string] $message=$null)
$timestamp = Get-Date -format \"yyyyMMdd_HH:mm:«»ss\"
switch($level) {
0 {Write-Output \"$timestamp : INFO : $message\" }
1 {Write-Output \"$timestamp : WARNING : $message\" }
2 {Write-Output \"$timestamp : ERROR : $message\" }
}
}
# This function Write an error on Host.
function GetError {
param ([string]$text = $null,
[int]$ExitNb = $null)
Write-Host \"$text FAILED: ERROR $ExitNb\"
Exit $ExitNb
}
# This function inform on the ouput
Function Create-LogInfo {
param([string] $Libelle =$null,
[string] $Status =$null)
$currentDate = date -Format \"dd/MM/yyyy - HH:mm:«»ss - \"
if ($libelle.length -lt \"7\"«»)
{
\"$currentDate $Libelle\" + \"`t`t: $Status\" >> $logfile
}
else
{
\"$currentDate $Libelle\" + \"`t: $Status\" >> $logfile
}
if ($error) {
$error >> $logfile
$error.clear()
}
}
# This function create an array for paths
function Add-Path {
param([string]$Path,[string]$label)
$d = New-Object PSObject
$d | Add-Member -Name Path -MemberType NoteProperty -Value $Path
$d | Add-Member -Name Label -MemberType NoteProperty -Value $label
return $d
}
# This function create an array for Rights
function Add-Rights {
param([string]$wmi,[string]$name)
$d = New-Object PSObject
$d | Add-Member -Name wmi -MemberType NoteProperty -Value $wmi
$d | Add-Member -Name name -MemberType NoteProperty -Value $name
return $d
}
# This function create an array for account
function Add-Account {
param([string]$account,[string]$label,[string]$desc)
$d = New-Object PSObject
$d | Add-Member -Name account -MemberType NoteProperty -Value $account
$d | Add-Member -Name desc -MemberType NoteProperty -Value $desc
return $d
}
# function create an array for Services
function Add-Service {
param([string]$name,[string]$shortname,[string]$desc,[string]$startup)
$d = New-Object PSObject
$d | Add-Member -Name name -MemberType NoteProperty -Value $name
$d | Add-Member -Name shortname -MemberType NoteProperty -Value $shortname
$d | Add-Member -Name desc -MemberType NoteProperty -Value $desc
$d | Add-Member -Name startup -MemberType NoteProperty -Value $startup
return $d
}
# Create User function
Function Create-LocalUser {
param([string]$user,[string]$password,[string]$desc)
$objOu = [ADSI]\"WinNT://localhost\"
$objUser = $objOU.Create(\"User\", $user)
#$objGrp = [ADSI](\"WinNT://localhost/Administrators\"«»)
$objUser.setpassword($password)
$objUser.SetInfo()
$objUser.description = \"$desc\"
$objUser.SetInfo()
#$objGroup.PSBase.Invoke(\"Add\",$objUser.PSBase.Path)
}
# Account array
$listofaccounts = @()
$listofaccounts += Add-Account -account \"svc_sqls_fcp\" -label \"\" -desc \"Service account for SQL Server\"
$listofaccounts += Add-Account -account \"svc_sqlb_fcp\" -label \"\" -desc \"Service account for SQL Server Browser\"
$listofaccounts += Add-Account -account \"svc_sqlrs_fcp\" -label \"\" -desc \"Service account for SQL Server Reporting Service\"
$listofaccounts += Add-Account -account \"svc_sqlft_fcp\" -label \"\" -desc \"Service account for SQL Server Full Text Search\"
# SQL Paths // Warning if you change Path here do not forget to change them in $CreateDB var.... !!!!!
$ListOfPaths = @()
$ListOfPaths += Add-Path -path \"D:\system_db\" -label \"System Files\"
$ListOfPaths += Add-Path -path \"D:\system_db_x86\" -label \"Shared System Files\"
$ListOfPaths += Add-Path -path \"D:\backup_db\" -label \"Backup directory\"
$ListOfPaths += Add-Path -path \"D:\config_db\" -label \"Config Directory\"
$ListOfPaths += Add-Path -path \"D:\user_db\" -label \"Data for SQL Server instance\"
$ListOfPaths += Add-Path -path \"D:\log_db\" -label \"Log for SQL Server instance\"
$ListOfPaths += Add-Path -path \"D:\temp_db\" -label \"Temp database for SQL Server instance\"
$ListOfPaths += Add-Path -path \"D:\temp_log_db\" -label \"Log of TempDB for SQL Server instance\"
# Local policies
$localrights = @()
$localrights += Add-Rights -wmi \"SeTcbPrivilege\" -name \"Act as part of the operating system\"
$localrights += Add-Rights -wmi \"SeIncreaseQuotaPrivilege\" -name \"Adjust memory quotas for a process\"
$localrights += Add-Rights -wmi \"SeCreateTokenPrivilege\" -name \"Create a token object\"
$localrights += Add-Rights -wmi \"SeImpersonatePrivilege\" -name \"Impersonate a client after authentication\"
$localrights += Add-Rights -wmi \"SeBatchLogonRight\" -name \"Log on as a batch job\"
$localrights += Add-Rights -wmi \"SeServiceLogonRight\" -name \"Log on as a service\"
$localrights += Add-Rights -wmi \"SeAssignPrimaryTokenPrivilege\" -name \"Replace a process level token\"
$localrights += Add-Rights -wmi \"SeManageVolumeNamePrivilege\" -name \"Perform volume maintenance tasks\"
$localrights += Add-Rights -wmi \"SeLockMemoryPrivilege\" -name \"Lock pages in memory\"
$localrights += Add-Rights -wmi \"SeChangeNotifyPrivilege\" -name \"Bypass traverse checking\"
# This function set privileges for account services
function Set-SePrivilege {
param ([string]$path=$null)
$setup = ($scriptdir+\"ntrights.exe\"«»)
foreach ($acc in $listofaccounts)
{
[string]$account = $acc.account
[string]$desc = $acc.desc
Create-LogInfo \"Set Privileges for $desc\" \"START\"
foreach ($right in $localrights) {
[string]$wmi = $right.wmi
[string]$desc = $right.name
$i = $setup + \" +r $wmi -u $account\"
Invoke-Expression $i
Create-LogInfo \"Give $desc right for $account\" \"SUCCESS\"
}
if ( $account -match \"svc_sqls_\" ) {
net localgroup Administrators $account /ADD
Create-LogInfo \"Modify ACLs\" \"START\"
$set_Right = cscript ($scriptdir+\"xcacls.vbs\"«») $data_disk /E /G $env:computername\`\"$account`\":F /SPEC B
if ($set_right) {
Create-LogInfo \"Give Full control on $data_disk for $account\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Give Full control on $data_disk for $account\"; GetError \"Error Giving Full control on $data_disk for $account\" $errorcode
}
}
}
}
$ServicesList = @()
$ServicesList += Add-Service -name \"SQL Server (MSSQLSERVER)\" -shortname \"MSSQLSERVER\" -desc \"Provides storage, processing and controlled access of data, and rapid transaction processing.\" -startup \"Automatic\"
$ServicesList += Add-Service -name \"SQL Server Browser\" -shortname \"SQLBrowser\" -desc \"Provides SQL Server connection information to client computers.\" -startup \"Automatic\"
$ServicesList += Add-Service -name \"SQL Server Reporting Services (MSSQLSERVER)\" -shortname \"ReportServer\" -desc \"Manages, executes, renders, schedules and delivers reports.\" -startup \"Automatic\"
$ServicesList += Add-Service -name \"SQL Full-text Filter Daemon Launcher (MSSQLSERVER)\" -shortname \"MSSQLFDLauncher\" -desc \"Service to launch full-text filter daemon process which will perform document filtering and word breaking for SQL Server full-text search. Disabling this service will make full-text search features of SQL Server unavailable.\" -startup \"Automatic\"
#########################################
#########################################
# #
# Do not edit anything after this point #
# #
#########################################
# clean previous Errors
if ($error) { $error.clear() }
$errorcode = 300
# Create log dir
if (!(Test-Path \"C:\log\\"«»)) {
New-Item -path \"C:\log\" -itemType \"Directory\"
}
# Create Directories
Create-LogInfo \"Create Folders\" \"START\"
Foreach ($dir in $ListOfPaths) {
[string]$name = $dir.label
if (New-Item -path $dir.path -itemType \"Directory\" -force) {
Create-LogInfo \"Create Folder for $name\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Create Folder for $name\" \"ERROR\"; GetError \"Can't create folder for $name\" $errorcode
}
}
# Add Firewall features and ports
Create-LogInfo \"Configure Firewall\" \"START\"
if ((netsh firewall set opmode enable) -and (netsh firewall add portopening TCP 1433 \"SQLServer($instanceName)\" enable subnet) -and (netsh firewall add portopening UDP 1434 \"SQLBrowser($instanceName)\" enable subnet) -and (netsh firewall set service fileandprint enable)) {
Create-LogInfo \"Configure Firewall\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configure Firewall\" \"ERROR\"; GetError \"Error Configuring Firewall\" $errorcode
}
# Add users
create-LogInfo \"Create accounts\" \"START\"
foreach ($account in $listofaccounts) {
[string]$a = $account.account
[string]$b = $account.desc
if (Create-LocalUser -user $account.account -password $SVC_Pwd -desc $account.desc) {
$errorcode++
Create-LogInfo \"Create $b\" \"SUCCESS\"
$acc = Get-WmiObject Win32_UserAccount -computername \".\" -filter \"LocalAccount=True AND` Name='$a'\"
$acc.PasswordChangeable=$false
$acc.PasswordExpires=$false
if ($acc.put()) {
$errorcode++
Create-LogInfo \"Modify $b\" \"SUCCESS\"
} else {
Create-LogInfo \"Modify $b\" \"ERROR\"; GetError \"Error modify the $b\" $errorcode
}
} else {
Create-LogInfo \"Create $b\" \"ERROR\"; GetError \"The account $b is not created\" $errorcode
}
}
$GetSVC = gwmi Win32_UserAccount -computername \".\" -filter \"LocalAccount=True\" | ?{ $_.name -match \"svc_\" }
if ($GetSVC.length -eq $listofaccounts.count) {
Create-LogInfo \"Create accounts\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Create accounts\" \"ERROR\"; GetError \"All accounts not created\" $errorcode
}
# Give correct privileges
Create-LogInfo \"Set Privileges\" \"START\"
if (Set-SePrivilege $scriptdir) {
Create-LogInfo \"Set Privileges\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Set Privileges\" \"ERROR\"; GetError \"Error Seting Privileges\" $errorcode
}
###########################
# #
# SQL Server installation #
# #
###########################
Create-LogInfo \"SQL Installation\" \"START\"
$inv = $sourcesdir + \"setup.exe /SAPWD=\" + $AdminPassword + \" /CONFIGURATIONFILE=\" + $scriptdir + \"config.ini\"
invoke-expression $inv
if (ps | ?{$_.name -eq \"sqlservr\"})
{
Create-LogInfo \"Install SQL\" \"SUCCESS\"
$errorcode++
}
else
{
Create-LogInfo \"Install SQL\" \"ERROR\"; GetError \"Install SQL\" $errorcode
}
############################
# #
# SQL Server Configuration #
# #
############################
# Network configuration
Create-LogInfo \"TCP/IP Configuration\" \"START\"
$HKML_IPall = \"HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\Tcp\IPAll\"
Set-ItemProperty $HKML_IPall -name \"TcpPort\" -value \"1433\"
Set-ItemProperty $HKML_IPall -name \"TcpDynamicPorts\" -value \"\"
$Get_TcpPort = (Get-ItemProperty $HKML_IPall).TcpPort
$Get_TcpDynamicPorts = (Get-ItemProperty $HKML_IPall).TcpDynamicPorts
if (($Get_TcpPort -eq 1433) -and ($Get_TcpDynamicPorts -eq \"\"«»)) {
Create-LogInfo \"Configuring TCP Port\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configuring TCP Port\" \"ERROR\"; GetError \"Error Configuring TCP Port\" $errorcode
}
# Load SQL CMDLETS
add-pssnapin sqlserverprovidersnapin100
add-pssnapin sqlservercmdletsnapin100
# Configuration of TempDB
Create-LogInfo \"Configure TempDB File\" \"START\"
Invoke-Sqlcmd -Query $TempDBmodify -Serverinstance .
$tempdbmaxsize = Invoke-Sqlcmd -Query $SelectTempDB -Serverinstance .
if ($tempdbmaxsize.max_size -eq 65536)
{
Create-LogInfo \"Configure TempDB File\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configure TempDB File\" \"ERROR\"; GetError \"Error Configure TempDB File\" $errorcode
}
Create-LogInfo \"Configure TempDB Log File\" \"START\"
Invoke-Sqlcmd -Query $TempLogDBmodify -Serverinstance .
$templogdbmaxsize = Invoke-Sqlcmd -Query $SelectTempLogDB -Serverinstance .
if ($templogdbmaxsize.max_size -eq 65536)
{
Create-LogInfo \"Configure TempDB Log File\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Configure TempDB Log File\" \"ERROR\"; GetError \"Error Configure TempDB Log File\" $errorcode
}
Create-LogInfo \"Auto-Configure TempDB\" \"START\"
Invoke-Sqlcmd -Query $TempDBadd -Serverinstance .
$NumberTempDBFiles = Invoke-Sqlcmd -Query $CountTempDBFiles -Serverinstance .
$NumberCPU = Invoke-Sqlcmd -Query $CpuCount -Serverinstance .
if ($NumberTempDBFiles.numcpu -eq $NumberCPU.cpu_count)
{
Create-LogInfo \"Auto-Configure TempDB\" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Auto-Configure TempDB\" \"ERROR\"; GetError \"Error Auto-Configure TempDB\" $errorcode
}
# Configure accounts for SQL Server Services
Create-LogInfo \"Configure SQL Services\" \"START\"
$i = 0
Foreach ($service in $ServicesList) {
$account = $listofaccounts[$i].account
[string]$servname = $service.shortname
$exec = C:\Temp\SQL\EXP\scripts\sc.exe config $servname obj= .\$account password= $SVC_Pwd
$i++
if ($exec -match \"SUCCESS\"«») {
Create-LogInfo \"Configure SQL Service ($servname) \" \"SUCCESS\"
$errorcode++
Stop-Service -name $servname -force
Start-Service -name $servname
$FullService = Get-Service -Name $servname
if ($FullService.Status -eq \"Running\"«»){
Create-LogInfo \"Restart SQL Service ($servname) \" \"SUCCESS\"
$errorcode++
} else {
Create-LogInfo \"Restart SQL Service ($servname)\" \"ERROR\"; GetError \"Error Restart SQL Service ($servname)\" $errorcode
}
} else {
Create-LogInfo \"Configure SQL Service ($servname)\" \"ERROR\"; GetError \"Error Configure SQL Service ($servname)\" $errorcode
}
}
Create-LogInfo \"Configure SQL Services\" \"SUCCESS\"
exit 0[/code:1]
Et le fichier de réponse pour l'installation:
[code:1];SQLSERVER2008 Configuration File
[SQLSERVER2008]
; Instance Name
INSTANCEID=\"MSSQLSERVER\"
INSTANCENAME=\"MSSQLSERVER\"
; Silent Install
ACTION=\"Install\"
FEATURES=SQLENGINE,REPLICATION,FULLTEXT,RS,BIDS,SSMS,SNAC_SDK,OCS,SSMS,ADV_SSMS
INDICATEPROGRESS=\"False\"
QUIET=\"True\"
QUIETSIMPLE=\"False\"
; Options
HELP=\"False\"
X86=\"False\"
ENU=\"True\"
ERRORREPORTING=\"False\"
SQMREPORTING=\"False\"
SQLCOLLATION=\"French_CI_AS\"
FARMADMINPORT=\"0\"
FILESTREAMLEVEL=\"0\"
ENABLERANU=\"False\"
TCPENABLED=\"1\"
NPENABLED=\"0\"
RSINSTALLMODE=\"DefaultNativeMode\"
IAcceptSQLServerLicenseTerms
; Directories
INSTALLSHAREDDIR=\"D:\system_db\"
INSTALLSHAREDWOWDIR=\"D:\system_db_x86\"
INSTANCEDIR=\"D:\system_db\"
SQLBACKUPDIR=\"D:\backup_db\"
SQLUSERDBDIR=\"D:\user_db\"
SQLUSERDBLOGDIR=\"D:\log_db\"
SQLTEMPDBDIR=\"D:\temp_db\"
SQLTEMPDBLOGDIR=\"D:\temp_log_db\"
; Accounts service
AGTSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
ISSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
SQLSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
RSSVCACCOUNT=\"NT AUTHORITY\NETWORK SERVICE\"
FTSVCACCOUNT=\"NT AUTHORITY\LOCAL SERVICE\"
; Service configuration
AGTSVCSTARTUPTYPE=\"Automatic\"
ISSVCSTARTUPTYPE=\"Automatic\"
SQLSVCSTARTUPTYPE=\"Automatic\"
BROWSERSVCSTARTUPTYPE=\"Automatic\"
RSSVCSTARTUPTYPE=\"Automatic\"
; Security
SQLSYSADMINACCOUNTS=\"Administrator\"
SECURITYMODE=\"SQL\"
[/code:1]<br><br>Message édité par: benduru, à: 17/04/12 09:56
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6298
- Remerciements reçus 68
il y a 11 ans 7 mois #11534
par Laurent Dardenne

Merci.
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Installation SQL Server 2008R2

Merci.
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
- sarasy
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 1
- Remerciements reçus 0
il y a 11 ans 5 mois #12164
par sarasy
Réponse de sarasy sur le sujet Re:Installation SQL Server 2008R2
Bonjour
Merci pour ce poste
Cela m'a permis de faire un script d'installation dans la journée
Jeeps64
Merci pour ce poste
Cela m'a permis de faire un script d'installation dans la journée
Jeeps64
Connexion ou Créer un compte pour participer à la conversation.
- SiSMik
- Auteur du sujet
- Hors Ligne
- Membre platinium
-
Réduire
Plus d'informations
- Messages : 492
- Remerciements reçus 0
il y a 11 ans 5 mois #12165
par SiSMik
Réponse de SiSMik sur le sujet Re:Installation SQL Server 2008R2
De rien, c'est là pour ça

Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6298
- Remerciements reçus 68
il y a 11 ans 5 mois #12166
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Installation SQL Server 2008R2
benduru écrit:
<br><br>Message édité par: Laurent Dardenne, à: 22/06/12 20:37
Ouai, mais les remerciements sont rares, savoureDe rien, c'est là pour ça

Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.108 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Contributions à la communauté
- Installation SQL Server 2008R2