SQL 2017 Powershell Install-Configure
SQL 2017 Powershell Install-Configure
http://rva.sqlpass.org/
SQL Community
Agenda
• SQL Server (setup)
• PowerShell Basics
Syntax
Commandlets
• Creating PowerShell Scripts
• Scripts 101
Prepare OS & install SQL
Post install configurations
Installation
&
Configuration
of
SQL Server
(what we’re trying to do…)
SQL Server Setup
Question:
Answer:
Umm….
Let me go find that Checklist.
SQL Setup Checklist
Requirements for SQL installs
• .NET 4.6 feature Automatic install for Win2016/SQL2016+
• SQL configuration file (for unattended installs)
• C:\Program Files\Microsoft SQL Server\...\ConfigurationFile.ini
• Service Accouts (MSA SQL2012) gMSA supported in SQL2016
• Firewall exceptions
Port Use
TCP 1433 Database Engine default install
UDP 1434 SQL Server Browser Service
TCP 1434 Dedicated Admin Connection (DAC)
TCP 80 & 443 HTTP/HTTPS for SSRS
TCP 139 & 445 SQL Filestream & Filetables
TCP 2383 Analysis Services
TCP 135 MS Distributed Transaction Coordinator
SQL Setup Checklist cont.
Post Install Configurations
• Add Admin Users/Groups • Alerts
• Rename the SA account • Severity 19-25
• Service Provider Name (SPN) • ID 18456 - Login Error
• Operators • ID 15247 - Permission Error
• Enable the SQL Agent service • ID 9002 - Log Full
• DBMail • ID 825 - Disk I/O Error
• Instant File Initialization (IFI) • Low disk space
• Enable CLR • Maintenance Jobs
• Import Custom SQL procedures • Backups
• Create Linked Servers • Reindex
• Audit to Server Security Log • CheckDB
• Add TempDB files FREE Maintenance Solutions
• Management Policies (PBM) http://minionware.net
• Encryption Certificates http://ola.hallengren.com
SQL 2016 ConfigurationFile.ini
SQL Server Setup Times
• aka PoSh or PS
• Shell and Integrated Scripting Environment
(ISE)
12 PowerShell constructs to
automate your SQL Server
Installation & Configuration
Installing SQL Server:
Install .NET Feature
Import-Module ServerManager;
# Get Windows Server Version
$WindowsVersion = [environment]::OSVersion.Version
Invoke-Expression $install;
Configuring SQL Server:
Import SQL PowerShell Module
SQL Server 2012-2014
Import-Module SQLPS -DisableNameChecking;
$SQLMem.Configuration.MaxServerMemory.ConfigValue = 20480;
$SQLMem.Configuration.MinServerMemory.ConfigValue = 10240;
$SQLMem.Configuration.NetworkPacketSize.ConfigValue = 1500;
$SQLMem.Configuration.OptimizeAdhocWorkloads.ConfigValue = 1;
$SQLMem.Alter();
PowerShell Gallery
https://www.powershellgallery.com/
Additional Resources:
http://powershell.sqlpass.org/