You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Install SQL Server with PowerShell Desired State Configuration
17
17
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.
19
23
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.
21
25
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.
23
29
24
30
The following items are required for this walkthrough:
25
31
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.
29
35
30
36
## Prerequisites
31
37
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.
33
39
34
40
## Install the SqlServerDsc DSC resource
35
41
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.
37
46
38
47
```PowerShell
39
48
Install-Module -Name SqlServerDsc
40
49
```
41
50
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`.
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:
61
70
62
71
```PowerShell
63
72
Configuration SQLInstall
@@ -66,7 +75,7 @@ Configuration SQLInstall
66
75
67
76
### Modules
68
77
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:
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:
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.
92
106
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.
97
109
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).
99
111
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.
101
113
102
-
#### Complete configuration
114
+
#### Finish configuration
103
115
104
116
```PowerShell
105
117
Configuration SQLInstall
@@ -130,40 +142,40 @@ Configuration SQLInstall
130
142
131
143
### Compile the configuration
132
144
133
-
Dot-source the configuration script:
145
+
Dotsource the configuration script:
134
146
135
147
```PowerShell
136
148
. .\SQLInstallConfiguration.ps1
137
149
```
138
150
139
-
Execute the configuration function:
151
+
Run the configuration function:
140
152
141
153
```PowerShell
142
154
SQLInstall
143
155
```
144
156
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.
146
158
147
159
### Deploy the configuration
148
160
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:
150
162
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.
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.
161
173
162
174
## Validate installation
163
175
164
176
### DSC
165
177
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**:
167
179
168
180
```PowerShell
169
181
PS C:\> Test-DscConfiguration
@@ -172,7 +184,7 @@ True
172
184
173
185
### Services
174
186
175
-
The services listing should now return SQL Server services
187
+
The services list now returns SQL Server services:
0 commit comments