programming4us
         
 
 
SQL Server

Installing SQL Server 2012 : The Installation Process (part 3) - Installing SQL Server 2012 Through the Command Line, Installing SQL Server 2012 Through PowerShell

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
6/29/2013 3:44:45 AM

3. Installing SQL Server 2012 Through the Command Line

In addition to installing SQL Server using the Setup Wizard , SQL Server can also be installed via the command line. Command-line installations of SQL Server enable you to install, upgrade, or remove SQL Server instances with little or no user interaction by specifying silent, basic, or full user interface.

Every option available in the graphical user interface using the Setup Wizard can also be configured via command-line parameters. Sixty-eight parameters are available when running Setup.exe from the command line to configure SQL Server features and services. You can find the complete list of command line parameters at http://msdn.microsoft.com/en-us/library/ms144259(v=SQL.110).aspx.

Table 7 lists commonly used parameters for SQL Server Engine Services command-line installations.

Table 7 Commonly Used SQL Server 2012 Setup Command Line Parameters

Parameter Description
/Q Optional. Specifies to run Setup in quiet mode for unattended installations.
/QS Optional. Specifies to run Setup and show progress through the UI. No input is accepted or errors displayed.
/UIMODE Optional. Specifies whether to display only essential dialog boxes during Setup.
/ACTION Required. Specifies a workflow.
Supported values: Install, Uninstall, or Upgrade.
/IACCEPTSQLSERVERLICENSETERMS Required. Accepts licensing terms.
/UPDATEENABLED Optional. Specifies whether to look for product updates.
Supported values: true and false or 1 and 0.
/UPDATESOURCE Optional. Specifies location of product updates.
Supported values: MU to search the Microsoft Update server, a folder path, a relative path, or a UNC share.
/CONFIGURATIONFILE Optional. Specifies a configuration file to be used.
/ERRORREPORTING Optional. Specifies error reporting opt-in option to Microsoft or a corporate report server.
Supported values: 1 = enabled; 0 = disabled.
/FEATURES or /ROLE Required. Specifies components to install or specifies a predetermined configuration known as the setup role.
/INSTALLSHAREDDIR Optional. Specifies a nondefault installation directory for 64-bit shared components.
/INSTANCEDIR Optional. Specifies a nondefault installation directory for instance-specific components.
/INSTANCEID Optional. Specifies a nondefault instance id.
/INSTANCENAME Required. Specifies an instance name.
/PID Optional. Specifies product key for the edition to be installed. If not specified, the Evaluation edition is installed.
/INSTALLSQLDATADIR Optional. Specifies the directory for SQL Server data (.mdf) files.
/SECURITYMODE Optional. Specifies security mode for SQL Server.
Default value: Windows-only authentication.Supported value: SQL.
/SAPWD Required if /SECURITYMODE=SQL. Specifies sa SQL Server account password.
/SQLUSERDBLOGDIR Optional. Specifies directory for SQL Server log files (*.ldf).
/SQLTEMPDBDIR Optional. Specifies directory for SQL Server tempdb data file.
/SQLTEMPDBLOGDIR Optional. Specifies directory for SQL Server tempdb log file.
/SQLBACKUPDIR Optional. Specifies directory for SQL Server backup files (*.bak, *.trn).
/SQLCOLLATION Optional. Specifies collation settings.
/SQLSVCACCOUNT Required. Specifies the startup account for the SQL Server service.
/SQLSVCPASSWORD Required. Specifies the password for the SQL Server service account.
/SQLSVCSTARTUPTYPE Optional. Specifies the startup mode of the SQL Server service.
Supported values: Automatic, Manual, and Disabled.
/SQLSYSADMINACCOUNTS Required. Specifies accounts to be added to the sysadmin role.

Only a handful of these command-line parameters are required to complete a SQL Server 2012 installation. Errors may generate for required configuration options if no value is specified for the corresponding parameter. For some parameters, default values are automatically set when a value is not explicitly defined. You can use the following script to install a standalone SQL Server 2012 instance with all Database Services components:

Setup.exe /q /ACTION=Install /FEATURES=SQL /INSTANCENAME=MSSQLSERVER
/SQLSVCACCOUNT="<<DomainName\UserName>"
/SQLSVCPASSWORD="<MyPassword>" 
/SQLSYSADMINACCOUNTS="<DomainName\UserName>" /AGTSVCACCOUNT="NT
AUTHORITY\Network
 Service" /IACCEPTSQLSERVERLICENSETERMS

Command-line installations can also use configuration files to reduce the number of command-line parameters and standardize SQL Server deployments. Configuration files are created during the installation process using the SQL Server installation wizard. The path where the configuration file is specified in the bottom section of the Ready to Install screen as shown in Figure 13, under the “Installing SQL Server 2012 Through the Installation Center” section.

Use the following script to execute an unattended installation of SQL Server:

Setup.exe /ConfigurationFile="<MyConfigurationFile.INI>"

4. Installing SQL Server 2012 Through PowerShell

You can also use PowerShell to perform unattended installs. Simple PowerShell scripts can be written to execute SQL Server 2012 Setup through its command-line interface. For example, you can execute the command-line script used in the previous section from the command line as follows:

$cmd = "d:\setup.exe /ACTION=install /Q /INSTANCENAME="MSSQLSERVER"
/IACCEPTSQLSERVERLICENSETERMS 
/FEATURES=SQLENGINE,SSMS 
/SQLSYSADMINACCOUNTS="YourDomain\Administrators"; 
Invoke-Expression -command $cmd | out-null;

More complex PowerShell scripts can be written for larger SQL Server 2012 deployments. A common approach is the use of PowerShell functions that accept the setup parameters necessary to perform unattended installations. These PowerShell functions are then executed in batches or inside a process that loops through a list of server names with corresponding parameters.

For example, a PowerShell function can be saved in a PowerShell script file and called along with setup parameters to perform a large scale unattended deployment of SQL Server 2012. Listing 1 provides an example of a PowerShell function that you can use for SQL Server 2012 unattended installations.

Listing 1 Install-Sql2012.ps1

The PowerShell function contained in the Install-SQL2012.ps1 script file is as follows:

Function Install-Sql2012
{
param
(
[Parameter(Position=0,Mandatory=$false)][string] $Path,
[Parameter(Position=1,Mandatory=$false)][string] $InstanceName = 
"MSSQLSERVER",
[Parameter(Position=2,Mandatory=$false)][string] $ServiceAccount,
[Parameter(Position=3,Mandatory=$false)][string] $ServicePassword,
[Parameter(Position=4,Mandatory=$false)][string] $SaPassword,
 [Parameter(Position=5,Mandatory=$false)][string] $LicenseKey,
[Parameter(Position=6,Mandatory=$false)][string] $SqlCollation =
 "SQL_Latin1_General_CP1_CI_AS",
[Parameter(Position=7,Mandatory=$false)][switch] $NoTcp,
[Parameter(Position=8,Mandatory=$false)][switch] $NoNamedPipes
)
#Build the setup command using the install mode
if ($Path -eq $null -or $Path -eq "")
{
#No path means that the setup is in the same folder
$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)
}
#Add current user as SysAdmin
$command += (’ /SQLSYSADMINACCOUNTS="{0}"’ -f
 [Security.Principal.WindowsIdentity]::GetCurrent().Name)
#Set the database collation
$command += (’ /SQLCOLLATION="{0}"’ -f $SqlCollation)
#Enable/Disable the TCP Protocol
if ($NoTcp)
{
$command += ‘ /TCPENABLED="0"'
}
else
{
$command += ‘ /TCPENABLED="1"'
}
#Enable/Disable the Named Pipes Protocol
if ($NoNamedPipes)
{
$command += ‘ /NPENABLED="0"'
}
else
{
$command += ‘ /NPENABLED="1"'
}
if ($PSBoundParameters['Debug'])
{
Write-Output $command
}
else
{
Invoke-Expression $command
}
}

After you download Listing 1 from the companion website, save it to a folder, for example c:\scripts. Because this is a file that you download from the Internet, you may be required to right-click the file and unblock it. When downloaded, execute this function by following these steps.

1. Launch the PowerShell command line with elevated Administrator privileges by right-clicking the PowerShell executable and selecting Run as Administrator. The PowerShell command line opens.
2. Verify that you can run and load unsigned PowerShell scripts and files. In the PowerShell command line, type get-executionpolicy to verify the current execution policy. If it is not set to RemoteSigned, you need to change it to this value by executing the following command:
 Set-ExecutionPolicy RemoteSigned
Next, load the PowerShell function in the script file by executing the following command:
 c:\scripts\Install-Sql2012.ps1
3. Notice the . and blank space before the script file path. The . and blank space is a required character to dot-source the script file.
4. Verify that the function has been loaded by issuing the following command:
get-command Install-Sql2012
A single row is returned showing CommandType Function and Name Install-Sql2012.
5. At this point you are ready to invoke the PowerShell function you just loaded. Invoke the Install-Sql2012 as follows:
Install-Sql2012 -Param1 Param1Value -Param2 Param2Value 

For example, the following command invokes the Install-Sql2012 function and sets the SQL Server service account and password along with the Instance Name and initiates a SQL Server 2012 installation.

Install-Sql2012 -Path d:\ -ServiceAccount "winserver\Administrator"
-ServicePassword "P@ssword"
-SaPassword "P@ssword"
-InstanceName "MyInstanceName"
Note
The SQL Server 2012 installation path may differ depending on your installation media.

Figure 15 shows the PowerShell command-line window with the steps necessary to invoke the Install-Sql2012 function.

Figure 15 PowerShell command line.

3.15
Other -----------------
- Installing SQL Server 2012 : Preparing the Server, Selecting the Edition
- SQL Server 2012 : SQL Server Architecture - SQL SERVER’S EXECUTION MODEL AND THE SQLOS
- SQL Server 2012 : SQL Server Architecture - THE LIFE CYCLE OF A QUERY (part 3) - A Simple Update Query
- SQL Server 2012 : SQL Server Architecture - THE LIFE CYCLE OF A QUERY (part 2) - Plan Cache
- SQL Server 2012 : SQL Server Architecture - THE LIFE CYCLE OF A QUERY (part 1)
- Protecting SQL Server Data : CELL-LEVEL ENCRYPTION - Views and Stored Procedures (part 2) - Creating the Stored Procedures
- Protecting SQL Server Data : CELL-LEVEL ENCRYPTION - Views and Stored Procedures (part 1) - Creating the View
- Protecting SQL Server Data : Implementing Cell-Level Encryption
- Protecting SQL Server Data : Preparing for Cell-Level Encryption
- Microsoft SQL Server 2008 R2 : Monitoring Replication (part 2) - New and Improved Peer-to-Peer Replication
- Microsoft SQL Server 2008 R2 : Monitoring Replication (part 1) - Replication Monitoring SQL Statements
- Microsoft SQL Server 2008 R2 : Scripting Replication
- Processing and Storing Data in SQL Server 2005 : Data Migration from One Data Store to Another Data Store
- Processing and Storing Data in SQL Server 2005 : Implementing the Record Failure Code
- Processing and Storing Data in SQL Server 2005 : Data Tracking Validation
- Processing and Storing Data in SQL Server 2005 : Updating the FileWorker Class
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 4) - Creating Subscriptions
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 3) - Horizontal and Vertical Filtering
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 2) - Creating a Publication
- Microsoft SQL Server 2008 R2 : Setting Up Replication (part 1) - Creating a Distributor and Enabling Publishing
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Celebrity Style, Fashion Trends, Beauty and Makeup Tips.