Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

61


Chapter 3: Installing SQL Server


3


$command = 'setup.exe /Action="Install"'
}
else
{
#Ensure that the path ends with a backslash
if(!$Path.EndsWith("\"))
{$Path += "\"
}
$command = $path + 'setup.exe /Action="Install"'
}
#Accept the license agreement - required for command line installs
$command += ' /IACCEPTSQLSERVERLICENSETERMS'
#Use the QuietSimple mode (progress bar, but not interactive)
$command += ' /QS'
#Set the features to be installed
$command += ' /FEATURES=SQLENGINE,CONN,BC,SSMS,ADV_SSMS'
#Set the Instance Name
$command += (' /INSTANCENAME="{0}"' -f $InstanceName)
#Set License Key only if a value was provided,
#else install Evaluation edition
if ($LicenseKey -ne $null -and $LicenseKey -ne "")
{
$command += (' /PID="{0}"' -f $LicenseKey)
}
#Check to see if a service account was specified
if ($ServiceAccount -ne $null -and $ServiceAccount -ne "")
{
#Set the database engine service account
$command += (' /SQLSVCACCOUNT="{0}" /SQLSVCPASSWORD="{1}"
/SQLSVCSTARTUPTYPE="Automatic"' -f
$ServiceAccount, $ServicePassword)
#Set the SQL Agent service account
$command += (' /AGTSVCACCOUNT="{0}" /AGTSVCPASSWORD="{1}"
/AGTSVCSTARTUPTYPE="Automatic"' -f
$ServiceAccount, $ServicePassword)
}
else
{
#Set the database engine service account to Local System
$command += ' /SQLSVCACCOUNT="NT AUTHORITY\SYSTEM"
/SQLSVCSTARTUPTYPE="Automatic"'
#Set the SQL Agent service account to Local System
$command += ' /AGTSVCACCOUNT="NT AUTHORITY\SYSTEM"
/AGTSVCSTARTUPTYPE="Automatic"'
}
#Set the server in SQL authentication mode if SA password was provided
if ($SaPassword -ne $null -and $SaPassword -ne "")
{
$command += (' /SECURITYMODE="SQL" /SAPWD="{0}"' -f $SaPassword)
Continues

c03.indd 61c03.indd 61 7/30/2012 4:10:08 PM7/30/2012 4:10:08 PM


http://www.it-ebooks.info
Free download pdf