Skip to content

Commit 17885d2

Browse files
authored
Merge pull request #8636 from TrishaMc/install-sql-server-with-powershell-desired-state-configuration2
Edit pass: Install sql server with powershell desired state configuration2
2 parents 997e20b + fc3b15b commit 17885d2

1 file changed

Lines changed: 48 additions & 36 deletions

File tree

docs/database-engine/install-windows/install-sql-server-with-powershell-desired-state-configuration.md

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Install SQL Server with PowerShell Desired State Configuration | Microsoft Docs"
3-
description: "Learn how to install SQL Server using PowerShell Desired State Configuration (DSC)."
3+
description: "Learn how to install SQL Server by using PowerShell Desired State Configuration (DSC)."
44
ms.custom: ""
55
ms.date: "10/26/2018"
66
ms.devlang: PowerShell
@@ -15,34 +15,43 @@ monikerRange: ">=sql-server-2016||=sqlallproducts-allversions"
1515

1616
# Install SQL Server with PowerShell Desired State Configuration
1717

18-
How many times have you clicked through the SQL Server installation interface just clicking the same old buttons, entering the same old information, not giving it much of a second thought? Then the installation finishes and the realization of "I forgot to specify the DBA group in the sysadmin role" hits. Now you have to spend precious time dropping into single-user mode, adding the appropriate users or groups, bringing SQL back up in multi-user mode, and testing. What's worse is now the confidence of the entire installation is shaken. "What else did I forget?" I for one have been in that situation more than once.
18+
Have you ever gone through the SQL Server installation interface just by selecting the same buttons, entering the same information, and not giving it a second thought? The installation finished, but you forgot to specify the DBA group in the **sysadmin** role. Then you had to do these things:
19+
* Drop into single-user mode.
20+
* Add the appropriate users or groups.
21+
* Bring SQL Server back up in multiuser mode.
22+
* Test.
1923

20-
Enter [PowerShell Desired State Configuration (DSC)](https://docs.microsoft.com/powershell/dsc/overview). Using DSC I can build one configuration template that can be reused over hundreds and thousands of servers. Depending on the build, I may have to tweak a few of the setup parameters, however that's not a big deal because I can still keep all of the standard settings in place. The beautiful thing is it eliminates the possibility that will forget to enter an important parameter after spending a sleepless night caring for my kids.
24+
What's worse is now the confidence of the entire installation is shaken. "What else did I forget?" you might ask yourself.
2125

22-
In this article, I will explore the initial setup of a standalone instance of SQL Server 2017 on Windows Server 2016 using the SqlServerDsc DSC resource. Some prior knowledge of DSC will be helpful as I will not explore the how DSC works.
26+
Read about [PowerShell Desired State Configuration (DSC)](https://docs.microsoft.com/powershell/dsc/overview). By using DSC, you build one configuration template that you can reuse over hundreds and thousands of servers. Depending on the build, you might have to tweak a few of the setup parameters. But that's not a significant issue because you can keep all of the standard settings in place. It eliminates the possibility that you'll forget to enter an important parameter.
27+
28+
This article explores the initial setup of a standalone instance of SQL Server 2017 on Windows Server 2016 by using the **SqlServerDsc** DSC resource. Some prior knowledge of DSC is helpful as we won't explore how DSC works.
2329

2430
The following items are required for this walkthrough:
2531

26-
- A machine running Windows Server 2016
27-
- SQL Server 2017 installation media
28-
- The SqlServerDsc DSC resource (version 10.0.0.0 is the current release at the time of this writing)
32+
- A machine that runs Windows Server 2016.
33+
- SQL Server 2017 installation media.
34+
- The **SqlServerDsc** DSC resource.
2935

3036
## Prerequisites
3137

32-
In most cases, DSC will be used to handle the prerequisite requirements. However, for the purposes of this demo, I will handle the prerequisites manually.
38+
In most cases, DSC is used to handle the prerequisite requirements. But for the purposes of this demo, we handle the prerequisites manually.
3339

3440
## Install the SqlServerDsc DSC resource
3541

36-
The [SqlServerDsc](https://www.powershellgallery.com/packages/SqlServerDsc) DSC resource can be downloaded from the [PowerShell Gallery](https://www.powershellgallery.com/) using the [Install-Module](https://docs.microsoft.com/powershell/module/powershellget/Install-Module?view=powershell-5.1) cmdlet. _Note: Ensure PowerShell is running "As Administrator" to install the module._
42+
Download the [SqlServerDsc](https://www.powershellgallery.com/packages/SqlServerDsc) DSC resource from the [PowerShell Gallery](https://www.powershellgallery.com/) by using the [Install-Module](https://docs.microsoft.com/powershell/module/powershellget/Install-Module?view=powershell-5.1) cmdlet.
43+
44+
> [!NOTE]
45+
> Make sure PowerShell is running **As Administrator** to install the module.
3746
3847
```PowerShell
3948
Install-Module -Name SqlServerDsc
4049
```
4150

42-
Obtain the SQL Server 2017 Installation Media
43-
Download the SQL Server 2017 installation media to the server. I downloaded SQL Server 2017 Enterprise from my Visual Studio subscription and copied the ISO to "C:\en_sql_server_2017_enterprise_x64_dvd_11293666.iso".
51+
### Get the SQL Server 2017 installation media
52+
Download the SQL Server 2017 installation media to the server. We downloaded SQL Server 2017 Enterprise from a Visual Studio subscription and copied the ISO to `C:\en_sql_server_2017_enterprise_x64_dvd_11293666.iso`.
4453

45-
Now the ISO must be extracted to a directory.
54+
Now the ISO must be extracted to a directory:
4655

4756
```PowerShell
4857
New-Item -Path C:\SQL2017 -ItemType Directory
@@ -57,7 +66,7 @@ Dismount-DiskImage -ImagePath 'C:\en_sql_server_2017_enterprise_x64_dvd_11293666
5766

5867
### Configuration
5968

60-
Create the configuration function that will be called to generate the [Managed Object Format (MOF)](https://docs.microsoft.com/windows/desktop/WmiSdk/managed-object-format--mof-) document(s).
69+
Create the configuration function that will be called to generate the [Managed Object Format (MOF)](https://docs.microsoft.com/windows/desktop/WmiSdk/managed-object-format--mof-) documents:
6170

6271
```PowerShell
6372
Configuration SQLInstall
@@ -66,7 +75,7 @@ Configuration SQLInstall
6675

6776
### Modules
6877

69-
Import the modules into the current session. These modules tell the configuration document how to build the MOF document(s) and tells the DSC engine how to apply the MOF document(s) to the server.
78+
Import the modules into the current session. These modules tell the configuration document how to build the MOF documents. They also tell the DSC engine how to apply the MOF documents to the server:
7079

7180
```PowerShell
7281
Import-DscResource -ModuleName SqlServerDsc
@@ -76,7 +85,7 @@ Import-DscResource -ModuleName SqlServerDsc
7685

7786
#### .NET Framework
7887

79-
SQL Server relies on the .NET framework, therefore we need to ensure it is installed prior to installing SQL Server. The WindowsFeature resource is utilized to install the Net-Framework-45-Core Windows Feature.
88+
SQL Server relies on the .NET Framework. So we need to make sure it's installed before we install SQL Server. The **WindowsFeature** resource is used to install the **Net-Framework-45-Core** Windows feature:
8089

8190
```PowerShell
8291
WindowsFeature 'NetFramework45'
@@ -88,18 +97,21 @@ WindowsFeature 'NetFramework45'
8897

8998
#### SqlSetup
9099

91-
The SqlSetup resource is used to tell DSC how to install SQL Server. The parameters required for a basic installation are:
100+
The **SqlSetup** resource is used to tell DSC how to install SQL Server. The parameters required for a basic installation are as follows:
101+
102+
- **InstanceName**. The name of the instance. Use **MSSQLSERVER** for a default instance.
103+
- **Features**. The features to install. In this example, we install only the **SQLEngine** feature.
104+
- **SourcePath**. The path to the SQL installation media. In this example, we stored the SQL installation media in `C:\SQL2017`. A network share can minimize the space used on the server.
105+
- **SQLSysAdminAccounts**. The users or groups who are to be a member of the **sysadmin** role. In this example, we grant the local Administrators group **sysadmin** access.
92106

93-
- **InstanceName**: The name of the instance. Utilize MSSQLSERVER for a default instance.
94-
- **Features** The features to install. In this example, I am only installing the SQLEngine feature.
95-
- **SourcePath**: The path to the SQL installation media. In this example, I stored the SQL installation media in "C:\SQL2017". A network share can be utilized to minimize the space used on the server.
96-
- **SQLSysAdminAccounts**: The users or groups who are to be a member of the sysadmin role. In this example, I am granting the local Administrators group sysadmin access. _Note: This configuration is not recommended in a high security environment._
107+
> [!NOTE]
108+
> We don't recommend this configuration in a high-security environment.
97109
98-
A full list and description of the parameters available on SqlSetup are available on the [SqlServerDsc GitHub respository](https://github.com/PowerShell/SqlServerDsc/tree/master#sqlsetup).
110+
A full list and description of the parameters available on **SqlSetup** are available on the [SqlServerDsc GitHub repository](https://github.com/PowerShell/SqlServerDsc/tree/master#sqlsetup).
99111

100-
The SqlSetup resource is odd because it only installs SQL and DOES NOT maintain the settings that are applied. For example, if the SQLSysAdminAccounts are specified at installation time, an admin could add or remove logins from to or from the sysadmin role and the SqlSetup resource wouldn't care. If it is desired that DSC enforces the membership of the sysadmin role, the [SqlServerRole](https://github.com/PowerShell/SqlServerDsc/tree/master#sqlserverrole) resource should be utilized.
112+
The **SqlSetup** resource installs only SQL Server and **doesn't** maintain the settings that are applied. An example is if the **SQLSysAdminAccounts** are specified at installation time. An admin might add or remove sign-ins to or from the **sysadmin** role. But the **SqlSetup** resource won't be affected. If you want DSC to enforce the membership of the **sysadmin** role, use the [SqlServerRole](https://github.com/PowerShell/SqlServerDsc/tree/master#sqlserverrole) resource.
101113

102-
#### Complete configuration
114+
#### Finish configuration
103115

104116
```PowerShell
105117
Configuration SQLInstall
@@ -130,40 +142,40 @@ Configuration SQLInstall
130142

131143
### Compile the configuration
132144

133-
Dot-source the configuration script:
145+
Dot source the configuration script:
134146

135147
```PowerShell
136148
. .\SQLInstallConfiguration.ps1
137149
```
138150

139-
Execute the configuration function:
151+
Run the configuration function:
140152

141153
```PowerShell
142154
SQLInstall
143155
```
144156

145-
A directory will be created in the working directory called "SQLInstall" and will contain a file call "localhost.mof". Examining the contents of the MOF will show the compiled DSC configuration.
157+
A directory called **SQLInstall** is created in the working directory. It contains a file called **localhost.mof**. Examine the contents of the MOF, which shows the compiled DSC configuration.
146158

147159
### Deploy the configuration
148160

149-
To start the DSC deployment of SQL Server, call the Start-DscConfiguration cmdlet. The parameters provided to the cmdlet are:
161+
To start the DSC deployment of SQL Server, call the **Start-DscConfiguration** cmdlet. The following parameters are provided to the cmdlet:
150162

151-
- **Path**: The path to the folder containing the MOF documents to deploy. (for example "C:\SQLInstall")
152-
- **Wait**: Wait for the configuration job to complete.
153-
- **Force**: Override any existing DSC configurations.
154-
- **Verbose**: Show the verbose output. Useful when pushing a configuration for the first time to aid in troubleshooting.
163+
- **Path**. The path to the folder that contains the MOF documents to deploy. An example is `C:\SQLInstall`.
164+
- **Wait**. Wait for the configuration job to finish.
165+
- **Force**. Override any existing DSC configurations.
166+
- **Verbose**. Show the verbose output. It's useful when you push a configuration for the first time to aid in troubleshooting.
155167

156168
```PowerShell
157169
Start-DscConfiguration -Path C:\SQLInstall -Wait -Force -Verbose
158170
```
159171

160-
As the configuration applies, the Verbose output will show you what is happening and give you a warm and fuzzy feeling that SOMETHING is happening. As long as no errors (red text) are thrown, when "Operation 'Invoke CimMethod' complete." is displayed on the screen, SQL should be installed.
172+
As the configuration applies, the verbose output shows you what's happening. As long as no errors (red text) are thrown, when **Operation 'Invoke CimMethod' complete** appears on the screen, SQL Server should be installed.
161173

162174
## Validate installation
163175

164176
### DSC
165177

166-
The [Test-DscConfiguration](https://docs.microsoft.com/powershell/module/psdesiredstateconfiguration/test-dscconfiguration) cmdlets can be utilized to determine if the current state of the server, in this case the SQL installation, meets the desired state. The result of Test-DscConfiguration should be "True".
178+
The [Test-DscConfiguration](https://docs.microsoft.com/powershell/module/psdesiredstateconfiguration/test-dscconfiguration) cmdlets can determine if the current state of the server meets the desired state. In this case, it's the SQL Server installation. The result of **Test-DscConfiguration** should be **True**:
167179

168180
```PowerShell
169181
PS C:\> Test-DscConfiguration
@@ -172,7 +184,7 @@ True
172184

173185
### Services
174186

175-
The services listing should now return SQL Server services
187+
The services list now returns SQL Server services:
176188

177189
```PowerShell
178190
PS C:\> Get-Service -Name *SQL*
@@ -198,6 +210,6 @@ PS C:\> & sqlcmd -S $env:COMPUTERNAME
198210

199211
[Windows PowerShell Desired State Configuration Overview](https://docs.microsoft.com/powershell/dsc/overview)
200212

201-
[Install SQL Server from the Command Prompt](../../database-engine/install-windows/install-sql-server-from-the-command-prompt.md)
213+
[Install SQL Server from the command prompt](../../database-engine/install-windows/install-sql-server-from-the-command-prompt.md)
202214

203-
[Install SQL Server using a configuration file](../../database-engine/install-windows/install-sql-server-using-a-configuration-file.md)
215+
[Install SQL Server by using a configuration file](../../database-engine/install-windows/install-sql-server-using-a-configuration-file.md)

0 commit comments

Comments
 (0)