Foreword |
|
xv | |
Preface |
|
xvii | |
Acknowledgments |
|
xix | |
About this book |
|
xxiii | |
About the authors |
|
xxvi | |
|
|
1 | (7) |
|
1.1 Why data professionals can't afford to ignore PowerShell |
|
|
1 | (2) |
|
A SQL Server DBA first win with PowerShell |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
4 | (1) |
|
1.4 Is this book for you? |
|
|
5 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
1.7 Being immediately effective with dbatools |
|
|
7 | (1) |
|
|
8 | (19) |
|
|
8 | (5) |
|
|
9 | (1) |
|
|
9 | (1) |
|
|
10 | (2) |
|
|
12 | (1) |
|
|
13 | (2) |
|
2.3 Understanding installation paths |
|
|
15 | (1) |
|
|
16 | (5) |
|
|
16 | (1) |
|
Trusting the PowerShell Gallery |
|
|
17 | (1) |
|
Installing dbatools using the PowerShell Gallery, all users |
|
|
18 | (1) |
|
PowerShell Gallery, local user |
|
|
19 | (1) |
|
PowerShell Gallery, offline install |
|
|
20 | (1) |
|
2.5 PowerShell Gallery alternatives |
|
|
21 | (2) |
|
Downloading a zipped archive |
|
|
21 | (1) |
|
|
22 | (1) |
|
2.6 How to find and use commands, the help system, and docs.dbatools.io |
|
|
23 | (2) |
|
|
23 | (1) |
|
|
23 | (1) |
|
|
23 | (2) |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
25 | (1) |
|
|
26 | (1) |
|
|
26 | (1) |
|
|
27 | (13) |
|
3.1 Why is a lab included in this book? |
|
|
27 | (1) |
|
3.2 Two options for building a dbatools lab environment |
|
|
28 | (1) |
|
3.3 Option 1: Windows lab |
|
|
29 | (6) |
|
Installation media for our lab |
|
|
29 | (1) |
|
|
30 | (3) |
|
|
33 | (2) |
|
Windows lab is ready for action |
|
|
35 | (1) |
|
3.4 Option 2: Quick demo environments using containers |
|
|
35 | (5) |
|
Running SQL Server in a container |
|
|
36 | (4) |
|
4 A gentle introduction to dbatools commands |
|
|
40 | (20) |
|
|
40 | (1) |
|
4.2 Checking the SQL connection |
|
|
41 | (1) |
|
|
41 | (2) |
|
4.4 Running your first dbatools command |
|
|
43 | (2) |
|
4.5 The - Sqllnstance parameter |
|
|
45 | (3) |
|
|
45 | (1) |
|
|
46 | (2) |
|
4.6 The - SqlCredential parameter |
|
|
48 | (6) |
|
Connecting to instances with SQL Server Authentication |
|
|
49 | (1) |
|
Saving the credential to use SQL Server Authentication with multiple commands |
|
|
50 | (1) |
|
Other methods of using credentials for SQL Server Authentication |
|
|
51 | (1) |
|
Connecting to instances with a different Windows account |
|
|
52 | (2) |
|
4.7 The ComputerName parameter |
|
|
54 | (2) |
|
Methods of listing the SQL services on multiple servers |
|
|
56 | (1) |
|
4.8 The - Credential parameter |
|
|
56 | (3) |
|
Listing services on a server using a different account at the command line |
|
|
56 | (1) |
|
Listing services on a server using a different account with a credential variable |
|
|
57 | (1) |
|
Listing SQL services by type |
|
|
58 | (1) |
|
4.9 Bonus parameter: EnableException |
|
|
59 | (1) |
|
|
59 | (1) |
|
|
60 | (19) |
|
|
60 | (4) |
|
5.2 Writing to a database |
|
|
64 | (11) |
|
Importing from a CSVfile to a database table |
|
|
64 | (4) |
|
Importing to a database table from a dbatools command |
|
|
68 | (2) |
|
Creating the database table first and then importing from a CSVfile |
|
|
70 | (3) |
|
Writing the results of other commands to a table |
|
|
73 | (1) |
|
Writing the results of other commands to an Azure SQL Database |
|
|
74 | (1) |
|
5.3 Copying tables, including their data |
|
|
75 | (3) |
|
|
76 | (2) |
|
|
78 | (1) |
|
6 Finding SQL Server instances on your network |
|
|
79 | (12) |
|
|
81 | (7) |
|
|
81 | (1) |
|
Finding instances using a list of targets |
|
|
82 | (3) |
|
Finding SQL Servers in an Active Directory domain |
|
|
85 | (1) |
|
Finding SQL Servers in your surrounding network |
|
|
86 | (2) |
|
6.2 Working with detailed results |
|
|
88 | (2) |
|
|
90 | (1) |
|
|
90 | (1) |
|
7 Inventorying your SQL estate |
|
|
91 | (11) |
|
|
92 | (2) |
|
|
94 | (1) |
|
|
95 | (1) |
|
|
96 | (4) |
|
Filtering databases returned from Get-DbaDatabase |
|
|
97 | (1) |
|
Filtering databases returned from Get-DbaDatabase by last backup time |
|
|
98 | (2) |
|
7.5 Putting it all together into a database |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
102 | (17) |
|
|
104 | (1) |
|
Version-specific RegSrvr.xmlfiles |
|
|
105 | (1) |
|
|
105 | (2) |
|
8.3 Central Management Server |
|
|
107 | (2) |
|
8.4 Inventory organization |
|
|
109 | (3) |
|
Importing advanced environment folder structures |
|
|
110 | (2) |
|
|
112 | (5) |
|
Adding new Registered Servers |
|
|
112 | (3) |
|
|
115 | (1) |
|
Moving Registered Servers |
|
|
116 | (1) |
|
Removing Registered Servers |
|
|
117 | (1) |
|
8.6 Registered Server groups |
|
|
117 | (1) |
|
|
118 | (1) |
|
|
119 | (14) |
|
|
120 | (4) |
|
9.2 Preventing login issues |
|
|
124 | (2) |
|
9.3 Logins, users, and permissions source control |
|
|
126 | (2) |
|
9.4 How was access gained? |
|
|
128 | (4) |
|
Finding nested Active Directory group access |
|
|
131 | (1) |
|
|
132 | (1) |
|
|
133 | (12) |
|
|
134 | (6) |
|
|
137 | (2) |
|
|
139 | (1) |
|
10.2 Reading backup files |
|
|
140 | (1) |
|
|
141 | (1) |
|
10.4 Pruning old backup files |
|
|
142 | (1) |
|
10.5 Testing your backups |
|
|
142 | (2) |
|
|
144 | (1) |
|
|
145 | (11) |
|
11.1 Limitations and considerations |
|
|
145 | (1) |
|
|
146 | (3) |
|
|
147 | (1) |
|
|
147 | (2) |
|
Output T-SQL restore scripts |
|
|
149 | (1) |
|
11.3 Restoring to custom data and log directories |
|
|
149 | (5) |
|
|
150 | (1) |
|
|
151 | (1) |
|
|
152 | (1) |
|
Restoring to a marked transaction |
|
|
152 | (1) |
|
Recovering a corrupt database |
|
|
153 | (1) |
|
|
154 | (1) |
|
|
154 | (1) |
|
|
154 | (1) |
|
|
155 | (1) |
|
|
156 | (8) |
|
|
156 | (1) |
|
|
157 | (1) |
|
12.3 When to use snapshots |
|
|
158 | (1) |
|
|
158 | (1) |
|
|
159 | (1) |
|
12.6 Rolling back the entire database from a snapshot |
|
|
160 | (1) |
|
12.7 Restoring certain objects or data from a snapshot |
|
|
161 | (1) |
|
|
162 | (1) |
|
|
162 | (1) |
|
|
163 | (1) |
|
13 Install and update SQL Server |
|
|
164 | (15) |
|
|
164 | (11) |
|
Benefits of automated installs 165' Local installs |
|
|
167 | (1) |
|
|
168 | (3) |
|
Customizing installation options |
|
|
171 | (1) |
|
ConfigurationFile and Configuration |
|
|
171 | (2) |
|
|
173 | (2) |
|
|
175 | (1) |
|
13.3 The importance of patching |
|
|
176 | (1) |
|
Fear of breaking everything |
|
|
176 | (1) |
|
Burdensome process leads to procrastination |
|
|
177 | (1) |
|
13.4 How we make it easier |
|
|
177 | (1) |
|
|
178 | (1) |
|
14 Preparing for disaster |
|
|
179 | (14) |
|
14.1 Exporting an entire instance |
|
|
180 | (7) |
|
|
184 | (2) |
|
Setting scripting options |
|
|
186 | (1) |
|
|
187 | (1) |
|
|
187 | (3) |
|
|
188 | (2) |
|
|
190 | (1) |
|
14.4 Exporting server configurations (sp_configure) |
|
|
191 | (1) |
|
|
192 | (1) |
|
15 Performing your first advanced SQL Server instance migration, part 1 |
|
|
193 | (2) |
|
|
194 | (1) |
|
|
195 | (20) |
|
|
197 | (1) |
|
Staging large databases for migration |
|
|
198 | (5) |
|
Other database migration options |
|
|
203 | (1) |
|
|
204 | (2) |
|
Performing your first advanced SQL Server instance migration, part 2 |
|
|
205 | (1) |
|
|
206 | (3) |
|
Which logins/groups are still needed"? |
|
|
208 | (1) |
|
16.2 SQL Agent objects: Jobs, operators, and more! |
|
|
209 | (4) |
|
|
213 | (1) |
|
|
214 | (1) |
|
|
214 | (1) |
|
17 High availability and disaster recovery |
|
|
215 | (14) |
|
|
215 | (4) |
|
Configuring log shipping with dbatools |
|
|
216 | (1) |
|
When log shipping goes bad: Gathering errors with dbatools |
|
|
217 | (1) |
|
Cutting over to a log shipped secondary database |
|
|
218 | (1) |
|
17.2 Windows Server Failover Cluster (WSFC) |
|
|
219 | (3) |
|
|
222 | (6) |
|
Creating an availability group with dbatools |
|
|
222 | (3) |
|
Explore existing availability groups |
|
|
225 | (2) |
|
|
227 | (1) |
|
|
228 | (1) |
|
18 PowerShell and SQL Server Agent |
|
|
229 | (20) |
|
18.1 Which to choose, CmdExec or PowerShell job steps? |
|
|
231 | (1) |
|
18.2 Creating Agent jobs to run PowerShell and dbatools |
|
|
232 | (6) |
|
Creating a SQL Server credential |
|
|
234 | (1) |
|
Creating a SQL Server Agent proxy |
|
|
235 | (2) |
|
|
237 | (1) |
|
18.3 Creating the SQL Server Agent job with a CmdExec job step |
|
|
238 | (2) |
|
|
240 | (8) |
|
Using default parameter values |
|
|
240 | (1) |
|
Ensuring that the Agent job fails when the PowerShell fails |
|
|
241 | (3) |
|
|
244 | (4) |
|
|
248 | (1) |
|
|
248 | (1) |
|
19 SQL Server Agent administration |
|
|
249 | (12) |
|
19.1 Listing SQL Server Agent information |
|
|
250 | (8) |
|
|
250 | (3) |
|
|
253 | (3) |
|
Finding specific Agent jobs |
|
|
256 | (2) |
|
19.2 Agent job results and history |
|
|
258 | (2) |
|
|
258 | (1) |
|
|
259 | (1) |
|
|
260 | (1) |
|
20 Creating and working with SQL Server Agent objects |
|
|
261 | (13) |
|
20.1 SQL Server Agent job creation |
|
|
261 | (9) |
|
|
262 | (1) |
|
|
263 | (1) |
|
|
264 | (2) |
|
|
266 | (1) |
|
|
266 | (3) |
|
|
269 | (1) |
|
20.2 Bonus Agent job commands |
|
|
270 | (3) |
|
|
271 | (1) |
|
|
272 | (1) |
|
|
273 | (1) |
|
|
273 | (1) |
|
|
274 | (11) |
|
|
275 | (1) |
|
|
275 | (1) |
|
|
276 | (1) |
|
|
276 | (1) |
|
|
277 | (7) |
|
Finding potential PII data |
|
|
277 | (2) |
|
Generating a configuration file for masking |
|
|
279 | (3) |
|
Applying static data masking |
|
|
282 | (1) |
|
Validating a data masking configuration file |
|
|
283 | (1) |
|
|
284 | (1) |
|
|
285 | (13) |
|
22.1 When should you use dbatools in DevOps? |
|
|
286 | (1) |
|
|
287 | (7) |
|
Exporting a DACPAC from an existing database |
|
|
287 | (2) |
|
|
289 | (1) |
|
|
290 | (4) |
|
22.3 Running dbatools (and PowerShell) on a CI/CD system |
|
|
294 | (3) |
|
|
295 | (1) |
|
Ensuring the dbatools module is available |
|
|
295 | (1) |
|
Understanding how to add parameters to the script |
|
|
295 | (2) |
|
|
297 | (1) |
|
23 Tracing SQL Server activity |
|
|
298 | (12) |
|
23.1 SQL Server trace and SQL Profiler |
|
|
299 | (2) |
|
Converting traces to Extended Events |
|
|
300 | (1) |
|
|
301 | (8) |
|
|
301 | (1) |
|
|
302 | (1) |
|
|
302 | (1) |
|
|
303 | (2) |
|
Starting and stopping Extended Event sessions |
|
|
305 | (1) |
|
|
306 | (2) |
|
Replicating Extended Event sessions to multiple instances |
|
|
308 | (1) |
|
|
308 | (1) |
|
|
309 | (1) |
|
24 Security and encryption |
|
|
310 | (18) |
|
24.1 Encrypting network connections |
|
|
310 | (6) |
|
|
311 | (4) |
|
|
315 | (1) |
|
24.2 Extended protection for authentication |
|
|
316 | (2) |
|
|
318 | (1) |
|
24.4 Transparent data encryption (TDE) |
|
|
319 | (4) |
|
|
319 | (2) |
|
|
321 | (2) |
|
24.5 Database backup encryption |
|
|
323 | (4) |
|
|
324 | (1) |
|
Backing up the database with a certificate |
|
|
325 | (1) |
|
Checking encryption information from the backup |
|
|
325 | (2) |
|
24.6 Multilayered security |
|
|
327 | (1) |
|
|
327 | (1) |
|
|
328 | (12) |
|
25.1 Types of compression |
|
|
328 | (1) |
|
25.2 How does rowstore data compression work? |
|
|
329 | (1) |
|
25.3 Why use data compression? |
|
|
330 | (1) |
|
25.4 It can't all be rainbows and unicorns: Compression drawbacks |
|
|
330 | (1) |
|
|
331 | (1) |
|
25.6 What should we compress? |
|
|
332 | (1) |
|
25.7 What makes a good candidate for compression? |
|
|
333 | (1) |
|
25.8 Dbatools, what should I compress? |
|
|
333 | (2) |
|
25.9 Compressing objects the old-fashioned way |
|
|
335 | (1) |
|
25.10 Dbatools to the rescue! |
|
|
336 | (1) |
|
25.11 Specifying the compression level |
|
|
337 | (1) |
|
|
338 | (1) |
|
|
339 | (1) |
|
26 Validating your estate with dbachecks |
|
|
340 | (10) |
|
26.1 What dbachecks and dbatools have in common |
|
|
340 | (1) |
|
|
341 | (2) |
|
26.3 Viewing all available checks |
|
|
343 | (1) |
|
26.4 Configuring the check parameters |
|
|
343 | (3) |
|
26.5 Storing the output data in a database |
|
|
346 | (3) |
|
|
347 | (1) |
|
|
348 | (1) |
|
Configuring the connection |
|
|
348 | (1) |
|
|
349 | (1) |
|
|
350 | (6) |
|
|
350 | (2) |
|
27.2 Service principals and access tokens |
|
|
352 | (1) |
|
|
353 | (1) |
|
|
353 | (2) |
|
|
355 | (1) |
|
|
355 | (1) |
|
28 Dbatools Configurations and logging |
|
|
356 | (7) |
|
28.1 Working with the configuration system |
|
|
356 | (3) |
|
Checking existing configurations |
|
|
356 | (1) |
|
Getting a specific configuration |
|
|
357 | (1) |
|
|
358 | (1) |
|
Changing a configuration value |
|
|
359 | (1) |
|
Resetting to default configuration values |
|
|
359 | (1) |
|
28.2 Taking the configs with you |
|
|
359 | (1) |
|
28.3 Using the logging system |
|
|
360 | (1) |
|
28.4 Exploring logged activity |
|
|
360 | (2) |
|
|
360 | (2) |
|
|
362 | (1) |
|
|
363 | (2) |
|
|
363 | (1) |
|
|
364 | (1) |
|
29.3 Contribute to dbatools |
|
|
364 | (1) |
|
|
364 | (1) |
Index |
|
365 | |