Tuesday, May 9, 2023

Install SQL server 2019 using PowerShell

Why do we use PowerShell for SQL Server installation?

The PowerShell is really a powerful tool that helps us to automate our tasks and reduce our time & also human error. PowerShell can help us during SQL Server installation in many ways:

PowerShell can help us to install SQL Server on multiple machines simultaneously in one go. Allows to save effort, time, and obviously cost also.
Using PowerShell, we can automate the whole installation and configuration of SQL Server settings. For example, creating multiple TempDB files as per CPUs, memory allocation as per available physical memory on the server, disk storage, security policies, etc.

Prerequisites for SQL Server 2019 installation

Before starting SQL Server installation, we need to check our system/server whether it is meeting minimum hardware and software requirements or not. 

Pre-requisites for SQL Server 2019 are given below:

Operating System
    Windows Server 2016 or later, 
    Windows 10 version 1709 or later, or 
    Linux distribution which supports SQL Server 2019.
Processor
    x64 processor with 2.0 GHz or higher speed.
Memory
    At least 2 GB of RAM but 8 GB is recommended.
Disk space
    At least 6 GB of free disk space but 10 GB is recommended.
.NET Framework
    .NET Framework 4.6.2 or later.
PowerShell
    PowerShell version 5.1 or later.

If we are ready with the above details, we can start SQL server installation on the system/server using PowerShell.

Steps to install SQL Server 2019 using PowerShell

Step 1: Download SQL Server 2019
    The edition of SQL Server depends on the requirement of the organization.

Step 2: 
    Open PowerShell as Administrator.

Step 3: 
    Now we need to install the SQL Server module for PowerShell.

Step 4: 
    Prepare for the SQL Server installation. Now we need to prepare the installation configuration file before starting the SQL Server installation. Actually, the configuration file contains settings that we want to enable during the SQL Server installation process. 

To create an SQL Server installation configuration file, we need to use below PowerShell script:

/*SQL Server 2019 Configuration File*/

[OPTIONS]
Action="Install"    --We can use INSTALL, UNINSTALL or UPGRADE
IAcceptSQLServerLicenseTerms="True"   -- To disable privacy statement during installation.
InstanceID="MSSQLSERVER"  -- We can use Named the Instance name also.
InstallMediaPath="E:\SQLServer2019"  --Installation Media Path
InstallSharedDir="C:\Program Files\Microsoft SQL Server"
InstallSharedWowDir="C:\Program Files (x86)\Microsoft SQL Server"
InstanceDIR="C:\Program Files\Microsoft SQL Server"
SQLCollation="SQL_Latin1_General_CP1_CI_AS"
SQLSvsAccount="NT Service\MSSQLSERVER"
SQLSvcPassword="YourPassword"
SQLSysAdminAccounts="YourDomain\YourUsername"
SecurityMode="SQL"
UpdateEnabled="False"

Step 5:
    Save the file with .ini extension like SQLConfig.ini.

Step 6:
    Now in PowerShell, specify the configuration file with Start-Process cmdlet to start SQL Server installation

Start-Process 
    -FilePath "E:\Softwares\SQLInstallConfigFile\SQLServerSetup.exe" 
    -ArgumentList "/ConfigurationFile= '"E:\SoftwaresSQLInstallConfigFile\SQLConfig.ini'"" -Wait

Step 7:
    Run the PowerShell script to start SQL Server Installation.

No comments:

Post a Comment

Featured Post

DBCC CLONEDATABASE: A Comprehensive Guide

The DBCC CLONEDATABASE command emerges as a formidable tool for administrators and developers in the field of database administration. The d...

Popular Posts