├── .vscode
└── launch.json
├── DAtabase Freespace.ps1
├── Database Collation.ps1
├── Export SQl user.ps1
├── LICENSE
├── Last Good DBCC CheckDb.ps1
├── Pester Test Backup Share - Server level.Tests.ps1
├── Pester Test Database Collation - Database Level.Tests.ps1
├── Pester Test Database Collation - Databases detailed.Tests.ps1
├── Pester Test Database collation - Server level.Tests.ps1
├── Pester Test Identity Usage - Column Level.Tests.ps1
├── Pester Test Identity Usage - Database Level.Tests.ps1
├── Pester Test Identity Usage - Server Level.Tests.ps1
├── Pester Test Last Backup - Individual.Tests.ps1
├── Pester Test Last Known good DBCC CheckDB - Database Level.Tests.ps1
├── Pester Test Last Known good DBCC CheckDB - Server Level and Time.Tests.ps1
├── Pester Test Last Known good DBCC CheckDB - Server Level.Tests.ps1
├── Pester Test Network Latency.Tests.ps1
├── Pester Test SPNs.Tests.ps1
├── Pester Test to XML and HTML.ps1
├── Pester test TempDb.Tests.ps1
├── README.md
├── Test Database Last Backup.ps1
├── Test SQLPath.ps1
└── TestConfig.json
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "type": "PowerShell",
6 | "request": "launch",
7 | "name": "PowerShell Launch (current file)",
8 | "script": "${file}",
9 | "args": [],
10 | "cwd": "${file}"
11 | },
12 | {
13 | "type": "PowerShell",
14 | "request": "attach",
15 | "name": "PowerShell Attach to Host Process",
16 | "processId": "${command:PickPSHostProcess}",
17 | "runspaceId": 1
18 | },
19 | {
20 | "type": "PowerShell",
21 | "request": "launch",
22 | "name": "PowerShell Interactive Session",
23 | "cwd": "${workspaceRoot}"
24 | }
25 | ]
26 | }
--------------------------------------------------------------------------------
/DAtabase Freespace.ps1:
--------------------------------------------------------------------------------
1 | Get-Help Get-DbaDatabaseFreespace -ShowWindow
2 |
3 | # details for a single instance
4 | $server = ''
5 | Get-DbaDatabaseFreespace -sqlserver $server
6 |
7 | # For a number of instances
8 | $SQLServers == '',''
9 | Get-DbaDatabaseFreespace -SqlInstance $SQLServers | Out-GridView
10 |
11 | ## Get the total size of a database
12 |
13 | $server = ''
14 | $dbName = ''
15 | $database = @{Name = 'Database'; Expression = {$dbname}}
16 | $FileSize = @{Name = 'FileSize'; Expression = {$_.Sum}}
17 | Get-DbaDatabaseFreespace -SqlServer $server -database $dbName |
18 | Select Database,FileSizeMB |
19 | Measure-Object FileSizeMB -Sum |
20 | Select $database ,Property, $filesize
21 |
22 | ## Total Size of all databases on an instance
23 |
24 | $server = ''
25 | $srv = Connect-DbaSqlServer $server
26 | $SizeonDisk = @()
27 | $srv.Databases |ForEach-Object {
28 | $dbName = $_.Name
29 | $database = @{Name = 'Database'; Expression = {$dbname}}
30 | $FileSize = @{Name = 'FileSize'; Expression = {$_.Sum}}
31 | $SizeOnDisk += Get-DbaDatabaseFreespace -SqlServer $server -database $dbName | Select Database,FileSizeMB | Measure-Object FileSizeMb -Sum | Select $database ,Property, $Filesize
32 | }
33 | $SizeOnDisk
34 |
35 | ## Sort the sizes
36 |
37 | $SizeOnDisk |Sort-Object Filesize -Descending
38 |
39 | ## Do things with thte results
40 |
41 | ## In a text file
42 | $SizeonDisk | Out-file C:\temp\Sizeondisk.txt
43 | Invoke-Item C:\temp\Sizeondisk.txt
44 | ## In a CSV
45 | $SizeonDisk | Export-Csv C:\temp\Sizeondisk.csv -NoTypeInformation
46 | notepad C:\temp\Sizeondisk.csv
47 | ## Email
48 | Send-MailMessage -SmtpServer $smtp -From DBATeam@TheBeard.local -To JuniorDBA-Smurf@TheBeard.Local `
49 | -Subject "Smurf this needs looking At" -Body $SizeonDisk
50 | ## Email as Attachment
51 | Send-MailMessage -SmtpServer $smtp -From DBATeam@TheBeard.local -To JuniorDBA-Smurf@TheBeard.Local `
52 | -Subject "Smurf this needs looking At" -Body "Smurf" -Attachments C:\temp\Sizeondisk.csv
53 |
54 | ## Only those 80% + full
55 |
56 | Get-DbaDatabaseFreespace -SqlServer $server | Where-Object {$_.PercentUsed -gt 80}
57 |
58 | ## File growth settings
59 |
60 | Get-DbaDatabaseFreespace -SqlServer $server | Where-Object {$_.AutoGrowType -ne 'Mb'}
61 |
62 | ## Get FileSize, Used and Free Space per database
63 | $server = ''
64 | $srv = Connect-DbaSqlServer $server
65 | $SizeonDisk = @()
66 | $srv.Databases |ForEach-Object {
67 | $dbName = $_.Name
68 | $database = @{Name = 'Database'; Expression = {$dbname}}
69 | $MB = @{Name = 'Mbs'; Expression = {$_.Sum}}
70 | $SizeOnDisk += Get-DbaDatabaseFreespace -SqlServer $server -database $dbName | Select Database,FileSizeMB, UsedSpaceMB, FreeSpaceMb | Measure-Object FileSizeMb , UsedSpaceMB, FreeSpaceMb -Sum | Select $database ,Property, $Mb
71 | }
72 | $SizeOnDisk
73 |
74 |
--------------------------------------------------------------------------------
/Database Collation.ps1:
--------------------------------------------------------------------------------
1 | Get-Help TestDbaDatabaseCollation -ShowWindow
2 |
3 | ## Test a server
4 |
5 | Test-DbaDatabaseCollation -SqlServer ''
6 |
7 | ## Only show teh mis matching databases
8 |
9 | (Test-DbaDatabaseCollation -SqlServer '').Where{$_.IsEqual -eq $false}
10 |
11 | ## Detailed info
12 |
13 | Test-DbaDatabaseCollation -SqlServer '' -Detailed
14 |
15 | ## Do thigns with results
16 | ## Output to a file
17 | Test-DbaDatabaseCollation -SqlServer '' -Detailed |Out-File C:\Temp\CollationCheck.txt
18 | ## Output to CSV
19 | Test-DbaDatabaseCollation -SqlServer '' -Detailed |Export-Csv C:\temp\CollationCheck.csv -NoTypeInformation
20 | ## Output to JSON
21 | Test-DbaDatabaseCollation -SqlServer '' -Detailed | ConvertTo-Json | Out-file c:\temp\CollationCheck.json
22 | ## Look at the files
23 | notepad C:\temp\CollationCheck.json
24 | notepad C:\temp\CollationCheck.csv
25 | notepad C:\temp\CollationCheck.txt
26 |
27 | ## Linux or SQL Auth
28 |
29 | $cred = Get-Credential
30 | Test-DbaDatabaseCollation -SqlServer LinuxvServer -Credential $cred -Detailed | Format-Table -AutoSize
--------------------------------------------------------------------------------
/Export SQl user.ps1:
--------------------------------------------------------------------------------
1 | Get-Help Export-SqlUser -ShowWindow
2 |
3 | ## Export users from an instance
4 |
5 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Users.sql
6 | Notepad C:\temp\SQL2016N2-Users.sql
7 |
8 | ## Export users from a database
9 |
10 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Fadetoblack.sql -Databases Fadetoblack
11 | notepad C:\temp\SQL2016N2-Fadetoblack.sql
12 |
13 | ## Export a single user from a database
14 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Lars-Fadetoblack.sql -User UlrichLars -Databases Fadetoblack
15 | notepad C:\temp\SQL2016N2-Lars-Fadetoblack.sql
16 |
17 | ## replace permissions and create a new file
18 | $LarsPermsFile = 'C:\temp\SQL2016N2-Lars-Fadetoblack.sql'
19 | $ManagerPermsFile = 'C:\temp\SQL2016N2-Manager-Fadetoblack.sql'
20 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath $LarsPermsFile -User UlrichLars -Databases Fadetoblack
21 | $ManagerPerms = Get-Content $LarsPermsFile
22 | ## replace permissions
23 | $ManagerPerms = $ManagerPerms.Replace('DENY INSERT ON [dbo].[Finances]','GRANT INSERT ON [dbo].[Finances]')
24 | $ManagerPerms = $ManagerPerms.Replace('DENY SELECT ON [dbo].[RealFinances]','GRANT SELECT ON [dbo].[RealFinances]')
25 | $ManagerPerms = $ManagerPerms.Replace('UlrichLars','TheManager')
26 | Set-Content -path $ManagerPermsFile -Value $ManagerPerms
27 | code-insiders $LarsPermsFile , $ManagerPermsFile
28 |
29 | ## export for a different version
30 | Export-SqlUser -SqlInstance SQL2016N2 -Databases FadetoBlack -User TheManager -FilePath C:\temp\SQL2016N2-Manager-2000.sql -DestinationVersion SQLServer2000
31 | Notepad C:\temp\SQL2016N2-Manager-2000.sql
32 |
33 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Users-2000.sql -DestinationVersion SQLServer2000
34 | Notepad C:\temp\SQL2016N2-Users-2000.sql
35 |
36 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Users-2005.sql -DestinationVersion SQLServer2005
37 | Notepad C:\temp\SQL2016N2-Users-2005.sql
38 |
39 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Users-2008.sql -DestinationVersion SQLServer2008/2008R2
40 | Notepad C:\temp\SQL2016N2-Users-2008.sql
41 |
42 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Users-2012.sql -DestinationVersion SQLServer2012
43 | Notepad C:\temp\SQL2016N2-Users-2012.sql
44 |
45 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Users-2014.sql -DestinationVersion SQLServer2014
46 | Notepad C:\temp\SQL2016N2-Users-2014.sql
47 |
48 | Export-SqlUser -SqlInstance SQL2016N2 -FilePath C:\temp\SQL2016N2-Users-2016.sql -DestinationVersion SQLServer2016
49 | Notepad C:\temp\SQL2016N2-Users-2016.sql
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/Last Good DBCC CheckDb.ps1:
--------------------------------------------------------------------------------
1 | get-help Get-DbaLastGoodCheckDb -ShowWindow
2 |
3 | ## one server
4 |
5 | Get-DbaLastGoodCheckDb -SqlServer ''
6 |
7 | ## one server detailed
8 |
9 | Get-DbaLastGoodCheckDb -SqlServer ''
10 |
11 | ## multiple servers
12 |
13 | $SQLServers = (Get-VM -ComputerName HYPERVServer | Where-Object {$_.Name -like '*SQL*' -and $_.State -eq 'Running'}).Name
14 | Get-DbaLastGoodCheckDb -SqlServer $SQLServers | Out-GridView
15 |
16 |
--------------------------------------------------------------------------------
/Pester Test Backup Share - Server level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe 'Testing Access to Backup Share' -Tag Server, Backup {
4 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
5 | # # $SQLServers = (Get-VM -ComputerName $Config.BackupShare.HyperV| Where-Object {$_.Name -like "*$($Config.BackupShare.NameSearch)*" -and $_.State -eq 'Running'}).Name
6 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
7 | $SQLServers = $SQLServers.Where{$_ -like "*$($Config.BackupShare.NameSearch)*"}
8 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
9 | ## create the test cases array
10 | $testCases= @()
11 | $SQLServers.ForEach{$testCases += @{Name = $_}}
12 | It " has access to Backup Share $($Config.BackupShare.BackupShare)" -TestCases $testCases -Skip:$($Config.BackupShare.Skip){
13 | Param($Name)
14 | Test-DBASqlPath -SqlServer $Name -Path $($Config.BackupShare.BackupShare) | Should Be $True
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Pester Test Database Collation - Database Level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing Database Collation" -Tag Database,Collation{
4 | if($($Config.CollationDatabase.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.CollationDatabase.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.CollationDatabase.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | $SQLServers = $SQLServers.Where{$_ -like "*$($Config.CollationDatabase.NameSearch)*"}
12 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
13 | foreach($Server in $SQLServers)
14 | {
15 | $CollationTests = Test-DbaDatabaseCollation -SqlServer $Server
16 | foreach($CollationTest in $CollationTests)
17 | {
18 | It "$($Collationtest.Server) database $($CollationTest.Database) should have the correct collation" {
19 | $CollationTest.IsEqual | Should Be $true
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Pester Test Database Collation - Databases detailed.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing Database Collation" -Tag Detailed,Database,Collation{
4 | if($($Config.CollationDatabaseDetailed.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.CollationDatabaseDetailed.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.CollationDatabaseDetailed.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | $SQLServers = $SQLServers.Where{$_ -like "*$($Config.CollationDatabaseDetailed.NameSearch)*"}
12 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
13 | foreach($Server in $SQLServers)
14 | {
15 | $CollationTests = Test-DbaDatabaseCollation -SqlServer $Server -Detailed
16 | foreach($CollationTest in $CollationTests)
17 | {
18 | It "$($Collationtest.Server) database $($CollationTest.Database) should have the correct collation of $($CollationTest.ServerCollation)" {
19 | $CollationTest.DatabaseCollation | Should Be $CollationTest.ServerCollation
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Pester Test Database collation - Server level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing Database Collation" -Tag Server,Collation{
4 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
5 | # $SQLServers = (Get-VM -ComputerName $Config.CollationServer.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.CollationServer.NameSearch)*" -and $_.State -eq 'Running'}).Name
6 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
7 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
8 | $testCases= @()
9 | $SQLServers.ForEach{$testCases += @{Name = $_}}
10 | It " databases have the right collation" -TestCases $testCases -Skip:$($Config.CollationServer.Skip){
11 | Param($Name)
12 | $Collation = Test-DbaDatabaseCollation -SqlServer $Name
13 | $Collation.IsEqual -contains $false | Should Be $false
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/Pester Test Identity Usage - Column Level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "$SQLServer - Testing how full the Identity columns are" -Tag Column, Detailed, Identity{
4 | if($Config.IdentityColumn.Skip)
5 | {continue}
6 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
7 | # $SQLServers = (Get-VM -ComputerName $Config.IdentityColumn.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.IdentityColumn.NameSearch)*" -and $_.State -eq 'Running'}).Name
8 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
9 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
10 | foreach($SQLServer in $SQLServers)
11 | {
12 | $dbs = (Connect-DbaSqlServer -SqlServer $SQLServer).Databases.Name
13 | foreach($db in $dbs)
14 | {
15 | Context "Testing $db" {
16 | $Tests = Test-DbaIdentityUsage -SqlInstance $SQLServer -Databases $db -WarningAction SilentlyContinue
17 | foreach($test in $tests)
18 | {
19 | It "$($test.Column) identity column in $($Test.Table) is less than $($Config.IdentityColumn.Percent) % full" {
20 | $Test.PercentUsed | Should BeLessThan $($Config.IdentityColumn.Percent)
21 | }
22 | }
23 | }
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/Pester Test Identity Usage - Database Level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing how full the Identity columns are" -Tag Database,Identity{
4 | if($Config.IdentityDatabase.Skip)
5 | {continue}
6 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
7 | # $SQLServers = (Get-VM -ComputerName $Config.IdentityColumn.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.IdentityColumn.NameSearch)*" -and $_.State -eq 'Running'}).Name
8 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
9 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
10 | foreach($SQLServer in $SQLServers)
11 | {
12 | Context "Testing $SQLServer" {
13 | $dbs = (Connect-DbaSqlServer -SqlServer $SQLServer).Databases.Name
14 | foreach($db in $dbs)
15 | {
16 | It "$db on $SQLServer identity columns are less than $($Config.IdentityDatabase.Percent) % full"{
17 | (Test-DbaIdentityUsage -SqlInstance $SQLServer -Databases $db -Threshold $($Config.IdentityDatabase.Percent) -WarningAction SilentlyContinue).PercentUsed | Should Be
18 | }
19 | }
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/Pester Test Identity Usage - Server Level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing how full the Identity columns are" -Tag Server,Identity {
4 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
5 | # $SQLServers = (Get-VM -ComputerName $Config.IdentityColumn.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.IdentityColumn.NameSearch)*" -and $_.State -eq 'Running'}).Name
6 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
7 | $SQLServers = $SQLServers.Where{$_.Name -like "*$($Config.IdentityColumn.NameSearch)*"}
8 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json";Break}
9 | $testCases= @()
10 | $SQLServers.ForEach{$testCases += @{Name = $_}}
11 | It " databases all have identity columns less than $($Config.IdentityServer.Percent) % full" -TestCases $testCases -Skip:$($Config.IdentityServer.Skip){
12 | Param($Name)
13 | (Test-DbaIdentityUsage -SqlInstance $Name -Threshold $($Config.IdentityServer.Percent) -WarningAction SilentlyContinue).PercentUsed | Should Be
14 | }
15 | }
--------------------------------------------------------------------------------
/Pester Test Last Backup - Individual.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 |
4 | Describe "Last Backup Test results" -Tag Database, Backup {
5 | if($($Config.LastBackup.Skip))
6 | {
7 | continue
8 | }
9 |
10 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
11 | # $SQLServers = (Get-VM -ComputerName $Config.LastBackup.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.LastBackup.NameSearch)*" -and $_.State -eq 'Running'}).Name
12 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
13 | $SQLServers = $SQLServers.Where{$_ -like "*$($Config.LastBackup.NameSearch)*"}
14 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
15 | $Results = $SQLservers.ForEach{Test-DbaLastBackup -SqlServer $_ -Destination $Config.LastBackup.TestServer -WarningAction SilentlyContinue}
16 |
17 | foreach($result in $results)
18 | {
19 | $skipexists = $false
20 | $skipdbcc = $false
21 | $SkipRestore = $false
22 | if($result.FileExists -ne $true -and $result.FileExists -ne $false)
23 | {
24 | $skipexists = $true
25 | }
26 | if($result.DBCCResult -like '*DBCC CHECKTABLE skipped for restored master*' -or $result.DBCCResult -eq 'Skipped')
27 | {
28 | $skipDBCC = $true
29 | }
30 | if($Result.RestoreResult -eq 'Restore not located on shared location')
31 | {
32 | $SkipRestore =$true
33 | }
34 | It "$($Result.Database) on $($Result.SourceServer) File Should Exist" -Skip:$skipExists {
35 | $Result.FileExists| Should Be 'True'
36 | }
37 | It "$($Result.Database) on $($Result.SourceServer) Restore should be Success" -skip:$SkipRestore{
38 | $Result.RestoreResult| Should Be 'Success'
39 | }
40 | It "$($Result.Database) on $($Result.SourceServer) DBCC should be Success" -Skip:$SkipDBCC{
41 | $Result.DBCCResult| Should Be 'Success'
42 | }
43 | It "$($Result.Database) on $($Result.SourceServer) Backup Should be less than $($Config.LastBackup.DaysOld) days old" {
44 | $Result.BackupDate| Should BeGreaterThan (Get-Date).AddDays(-$($Config.LastBackup.DaysOld) )
45 | }
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Pester Test Last Known good DBCC CheckDB - Database Level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing Last Known Good DBCC" -Tag Database, DBCC{
4 | if($($Config.DBCCDatabase.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.DBCCDatabase.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.DBCCDatabase.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | $SQLServers = $SQLServers.Where{$_ -like "*$($Config.DBCCDatabase.NameSearch)*"}
12 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
13 | foreach($Server in $SQLServers)
14 | {
15 | $DBCCTests = Get-DbaLastGoodCheckDb -SqlServer $Server -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
16 | foreach($DBCCTest in $DBCCTests)
17 | {
18 | It "$($DBCCTest.SQLInstance) database $($DBCCTest.Database) had a successful CheckDB"{
19 | $DBCCTest.Status | Should Be 'Ok'
20 | }
21 | It "$($DBCCTest.SQLInstance) database $($DBCCTest.Database) had a CheckDB run in the last $($Config.DBCCDatabase.Daysold) days" {
22 | $DBCCTest.DaysSinceLastGoodCheckdb | Should BeLessThan $($Config.DBCCDatabase.Daysold)
23 | $DBCCTest.DaysSinceLastGoodCheckdb | Should Not BeNullOrEmpty
24 | }
25 | It "$($DBCCTest.SQLInstance) database $($DBCCTest.Database) has Data Purity Enabled" {
26 | $DBCCTest.DataPurityEnabled| Should Be $true
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/Pester Test Last Known good DBCC CheckDB - Server Level and Time.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing Last Known Good DBCC" -Tag Detailed,DBCC{
4 | if($($Config.DBCCServerTime.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.DBCCServerTime.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.DBCCServerTime.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | $SQLServers = $SQLServers.Where{$_ -like "*$($Config.DBCCServerTime.NameSearch)*" }
12 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
13 | $testCases= @()
14 | $SQLServers.ForEach{$testCases += @{Name = $_}}
15 | It " databases have all had a successful CheckDB" -TestCases $testCases {
16 | Param($Name)
17 | $DBCC = Get-DbaLastGoodCheckDb -SqlServer $Name -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
18 | ($DBCC.LastGoodCheckDb -contains $null) | Should Be $false
19 | }
20 | It " databases have all had a CheckDB run in the last $($Config.DBCCServerTime.Daysold) days" -TestCases $testCases {
21 | Param($Name)
22 | $DBCC = Get-DbaLastGoodCheckDb -SqlServer $Name -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
23 | ($DBCC | Measure-Object -Property DaysSinceLastGoodCheckdb -Maximum).Maximum | Should BeLessThan $($Config.DBCCServerTime.Daysold)
24 | $DBCC.ForEach{$_.DaysSinceLastGoodCheckdb | Should Not BeNullOrEmpty}
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/Pester Test Last Known good DBCC CheckDB - Server Level.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing Last Known Good DBCC" -Tag Server,DBCC {
4 | if($($Config.DBCCServer.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.DBCCServer.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.DBCCServer.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | $SQLServers.Where{$_ -like "*$($Config.DBCCServer.NameSearch)*"}
12 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
13 | $testCases= @()
14 | $SQLServers.ForEach{$testCases += @{Name = $_}}
15 | It " databases have all had a successful CheckDB within the last 7 days" -TestCases $testCases {
16 | Param($Name)
17 | $DBCC = Get-DbaLastGoodCheckDb -SqlServer $Name -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
18 | $DBCC.Status -contains 'New database, not checked yet'| Should Be $false
19 | $DBCC.Status -contains 'CheckDb should be performed'| Should Be $false
20 | }
21 | }
--------------------------------------------------------------------------------
/Pester Test Network Latency.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing Network Latency" -Tag Server,Network {
4 | if($($Config.Network.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.Network.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.Network.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | $SQLServers = $SQLServers.Where{$_ -like "*$($Config.Network.NameSearch)*"}
12 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
13 | foreach($Server in $SQLServers)
14 | {
15 | Context "Testing $Server Spns"{
16 | $Latency = Test-DBANetworkLatency -SqlServer $Server
17 | It "$Server Total Latency should be less than $($Config.Network.Latency)" {
18 | $Latency.AvgMs | Should BeLessThan $($Config.Network.Latency)
19 | }
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/Pester Test SPNs.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing SPNs" -Tag Server,SPN {
4 | if($($Config.SPN.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.SPN.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.SPN.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
12 | foreach($Server in $SQLServers)
13 | {
14 | Context "Testing $Server Spns"{
15 | $SPNs = Test-DbaSpn -ComputerName $Server -Domain $($Config.SPN.DomainName)
16 | foreach($SPN in $SPNs)
17 | {
18 | It "$Server should have SPN for $($SPN.RequiredSPN) for $($SPN.InstanceServiceAccount)" {
19 | $SPN.Error | Should Be 'None'
20 | }
21 | }
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Pester Test to XML and HTML.ps1:
--------------------------------------------------------------------------------
1 | $Config = (Get-Content TestConfig.JSON) -join "`n" | ConvertFrom-Json
2 | $Date = Get-Date -Format ddMMyyyHHmmss
3 | $XML = $Config.XMLHTML.Path + $Config.XMLHTML.FileName + "_$Date.xml"
4 | Set-Location $Config.XMLHTML.pesterLocation
5 | Invoke-Pester -OutputFile $xml -OutputFormat NUnitXml
6 |
7 | #download and extract ReportUnit.exe
8 | Set-Location $Config.XMLHTML.Path
9 | $url = 'http://relevantcodes.com/Tools/ReportUnit/reportunit-1.2.zip'
10 | $reportunit = $Config.XMLHTML.Path + '\reportunit.exe'
11 | if((Test-Path $reportunit) -eq $false)
12 | {
13 | (New-Object Net.WebClient).DownloadFile($url,$fullPath)
14 | Expand-Archive -Path $fullPath -DestinationPath $Config.XMLHTML.Path
15 | }
16 |
17 | #run reportunit against report.xml and display result in browser
18 | $HTML = $Config.XMLHTML.Path + 'index.html'
19 | & .\reportunit.exe $Config.XMLHTML.Path
20 | Invoke-Item $HTML
21 |
--------------------------------------------------------------------------------
/Pester test TempDb.Tests.ps1:
--------------------------------------------------------------------------------
1 | # Requires -Version 4
2 | # Requires module dbatools
3 | Describe "Testing TempDb" -Tag Server,TempDb {
4 | if($($Config.TempDb.Skip))
5 | {
6 | continue
7 | }
8 | ## This is getting a list of server name from Hyper-V - You can chagne this to a list of SQL instances
9 | # $SQLServers = (Get-VM -ComputerName $Config.TempDb.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.TempDb.NameSearch)*" -and $_.State -eq 'Running'}).Name
10 | $SQLServers = 'ROB-XPS', 'ROB-XPS\DAVE', 'ROB-XPS\SQL2016'
11 | if(!$SQLServers){Write-Warning "No Servers to Look at - Check the config.json"}
12 | foreach($Server in $SQLServers)
13 | {
14 | Context "Testing $Server TempDb"{
15 | $TempDbTests = Test-DBATempDbConfiguration -SqlServer $Server
16 |
17 | It "$Server should have TF118 enabled" -Skip:$($Config.TempDb.Skip118){
18 | $TempDbTests[0].CurrentSetting | Should Be $TempDbTests[0].Recommended
19 | }
20 | It "$Server should have $($TempDbTests[1].Recommended) TempDB Files" -Skip:$($Config.TempDb.SkipNumberofFiles){
21 | $TempDbTests[1].CurrentSetting | Should Be $TempDbTests[1].Recommended
22 | }
23 | It "$Server should not have TempDB Files autogrowth set to percent" -Skip:$($Config.TempDb.SkipFileGrowthPercent){
24 | $TempDbTests[2].CurrentSetting | Should Be $TempDbTests[2].Recommended
25 | }
26 | It "$Server should not have TempDB Files on the C Drive" -Skip:$($Config.TempDb.SkipFilesonC){
27 | $TempDbTests[3].CurrentSetting | Should Be $TempDbTests[3].Recommended
28 | }
29 | It "$Server should not have TempDB Files with MaxSize Set" -Skip:$($Config.TempDb.SkipFileMaxSize){
30 | $TempDbTests[4].CurrentSetting | Should Be $TempDbTests[4].Recommended
31 | }
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dbatools-scripts
2 | Holds a number of scripts for use with dbatools mainly from the blog posts at [https://sqldbawithabeard.com/tag/dbatools](https://sqldbawithabeard.com/tag/dbatools )
3 |
4 | # Pester Tests
5 |
6 | At present there are the following tests
7 |
8 | - Pester Test Backup Share - Server level.Tests.ps1
9 | - Pester Test Database Collation - Database Level.Tests.ps1
10 | - Pester Test Database Collation - Databases detailed.Tests.ps1
11 | - Pester Test Database collation - Server level.Tests.ps1
12 | - Pester Test Identity Usage - Column Level.Tests.ps1
13 | - Pester Test Identity Usage - Database Level.Tests.ps1
14 | - Pester Test Identity Usage - Server Level.Tests.ps1
15 | - Pester Test Last Backup - Individual.Tests.ps1
16 | - Pester Test Last Known good DBCC CheckDB - Database Level.Tests.ps1
17 | - Pester Test Last Known good DBCC CheckDB - Server Level and - Time.Tests.ps1
18 | - Pester Test Last Known good DBCC CheckDB - Server Level.Tests.ps1
19 | - Pester Test Network Latency.Tests.ps1
20 | - Pester Test SPNs.Tests.ps1
21 | - Pester test TempDb.Tests.ps1
22 |
23 | All require dbatools and PowerShell version 4 or above. You can get dbatools from [https:\\dbatools.io](https://dbatools.io)
24 |
25 | The pester tests are controlled by the TestConfig.Json file.
26 |
27 | Alter the values or settigns to fit what you need to test. Setting the Skip value to true will skip the entire test
28 |
29 | Then change directory to the folder holding the files and run
30 |
31 | ```PowerShell
32 | $Config = (Get-Content TestConfig.JSON) -join "`n" | ConvertFrom-Json
33 | ```
34 |
35 | Then all you need to do is run
36 |
37 | ```
38 | Invoke-Pester
39 | ```
40 |
41 | These scripts use gather Server names from a Hyper-V host so if you wish to use that then set the HyperV to your Hyper-V Hostname and NameSearch to perform a wildcard search on your VM Names
42 |
43 | ```json
44 | "HyperV": "beardnuc",
45 | "NameSearch":"SQL2016N3",
46 | ```
47 |
48 | If you wish to use a different method to gather your SQL instances then you will need to open the folder in VS Code and use the search and replace to replace the below code
49 |
50 | ```PowerShell
51 | # $SQLServers = (Get-VM -ComputerName $Config.Network.HyperV -ErrorAction SilentlyContinue| Where-Object {$_.Name -like "*$($Config.Network.NameSearch)*" -and $_.State -eq 'Running'}).Name
52 | ```
53 |
54 | with the method you choose. You can use the TestConfig.Json to filter in the same way if you wish
55 |
56 | You can also output to HTML using reportunit.exe in the Pester Test To XML and HTML file
--------------------------------------------------------------------------------
/Test Database Last Backup.ps1:
--------------------------------------------------------------------------------
1 | Get-Help Test-DbaLastBackup -ShowWindow
2 |
3 | #one SQL Server but want to ensure that you are testing your backup files then as along as you have the diskspace you can simply run
4 | Test-DbaLastBackup -SqlServer $ServerPath
5 |
6 | ## Test backups on a different server
7 | Test-DbaLastBackup -SqlServer '' -Destination ''| OGV
8 |
9 | ## Limit the size of the databases that are tested and put results to a file
10 |
11 | Test-DbaLastBackup -SqlServer ''-Destination '' -MaxMB 5 | Out-File C:\temp\Test-Restore.txt
12 | notepad C:\temp\Test-Restore.txt
13 |
14 | ## to csv
15 |
16 | Test-DbaLastBackup -SqlServer '' -Destination '' -MaxMB 5 | Export-Csv C:\temp\Test-Restore.csv -NoTypeInformation
17 |
18 | ## to json
19 |
20 | Test-DbaLastBackup -SqlServer '' -Destination ''| ConvertTo-Json | Out-file c:\temp\test-results.json
21 |
22 | ## to HTML
23 |
24 | $Results = Test-DbaLastBackup -SqlServer '' -Destination ''
25 | $Results | ConvertTo-Html | Out-File c:\temp\test-results.html
26 |
27 | ## TO a colour coded excel
28 |
29 | Import-Module dbatools
30 |
31 | $TestServer = ''
32 | $Server = ''
33 | ## Run the test and save to a variable
34 | $Results = Test-DbaLastBackup -SqlServer $server -Destination $TestServer
35 | # Set the filename
36 | $TestDate = Get-Date
37 | $Date = Get-Date -Format ddMMyyy_HHmmss
38 | $filename = 'C:\Temp\TestResults_' + $Date + '.xlsx'
39 | # Create a .com object for Excel
40 | $xl = new-object -comobject excel.application
41 | $xl.Visible = $true # Set this to False when you run in production
42 | $wb = $xl.Workbooks.Add() # Add a workbook
43 | $ws = $wb.Worksheets.Item(1) # Add a worksheet
44 | $cells=$ws.Cells
45 | $col = 1
46 | $row = 3
47 | ## Create a legenc
48 | $cells.item($row,$col)="Legend"
49 | $cells.item($row,$col).font.size=16
50 | $Cells.item($row,$col).Columnwidth = 10
51 | $Cells.item($row,$col).Interior.ColorIndex = 34
52 | $row ++
53 | $cells.item($row,$col)="True or Success"
54 | $cells.item($row,$col).font.size=12
55 | $Cells.item($row,$col).Columnwidth = 10
56 | $Cells.item($row,$col).Interior.ColorIndex = 10
57 | $row ++
58 | $cells.item($row,$col)="False or Failed"
59 | $cells.item($row,$col).font.size=12
60 | $Cells.item($row,$col).Columnwidth = 10
61 | $Cells.item($row,$col).Interior.ColorIndex= 3
62 | $row ++
63 | $cells.item($row,$col)="Skipped"
64 | $cells.item($row,$col).font.size=12
65 | $Cells.item($row,$col).Columnwidth = 10
66 | $Cells.item($row,$col).Interior.ColorIndex= 16
67 | $row ++
68 | $cells.item($row,$col)="Backup Under 7 days old"
69 | $cells.item($row,$col).font.size=12
70 | $Cells.item($row,$col).Columnwidth = 10
71 | $Cells.item($row,$col).Interior.ColorIndex= 4
72 | $row ++
73 | $cells.item($row,$col)="Backup Over 7 days old"
74 | $cells.item($row,$col).font.size=12
75 | $Cells.item($row,$col).Columnwidth = 10
76 | $Cells.item($row,$col).Interior.ColorIndex= 3
77 | ## Create a header
78 | $col ++
79 | $row = 3
80 | $cells.item($row,$col)="Source Server"
81 | $cells.item($row,$col).font.size=16
82 | $Cells.item($row,$col).Columnwidth = 10
83 | $Cells.item($row,$col).Interior.ColorIndex= 34
84 | $col ++
85 | $cells.item($row,$col)="Test Server"
86 | $cells.item($row,$col).font.size=16
87 | $Cells.item($row,$col).Columnwidth = 10
88 | $Cells.item($row,$col).Interior.ColorIndex= 34
89 | $col ++
90 | $cells.item($row,$col)="Database"
91 | $cells.item($row,$col).font.size=16
92 | $Cells.item($row,$col).Columnwidth = 10
93 | $Cells.item($row,$col).Interior.ColorIndex= 34
94 | $col ++
95 | $cells.item($row,$col)="File Exists"
96 | $cells.item($row,$col).font.size=16
97 | $Cells.item($row,$col).Columnwidth = 10
98 | $Cells.item($row,$col).Interior.ColorIndex= 34
99 | $col ++
100 | $cells.item($row,$col)="Restore Result"
101 | $cells.item($row,$col).font.size=16
102 | $Cells.item($row,$col).Columnwidth = 10
103 | $Cells.item($row,$col).Interior.ColorIndex= 34
104 | $col ++
105 | $cells.item($row,$col)="DBCC Result"
106 | $cells.item($row,$col).font.size=16
107 | $Cells.item($row,$col).Columnwidth = 10
108 | $Cells.item($row,$col).Interior.ColorIndex= 34
109 | $col ++
110 | $cells.item($row,$col)="Size Mb"
111 | $cells.item($row,$col).font.size=16
112 | $Cells.item($row,$col).Columnwidth = 10
113 | $Cells.item($row,$col).Interior.ColorIndex= 34
114 | $col ++
115 | $cells.item($row,$col)="Backup Date"
116 | $cells.item($row,$col).font.size=16
117 | $Cells.item($row,$col).Columnwidth = 10
118 | $Cells.item($row,$col).Interior.ColorIndex= 34
119 | $col ++
120 | $cells.item($row,$col)="Backup Files"
121 | $cells.item($row,$col).font.size=16
122 | $Cells.item($row,$col).Columnwidth = 10
123 | $Cells.item($row,$col).Interior.ColorIndex= 34
124 | $col = 2
125 | $row = 4
126 | foreach($result in $results)
127 | {
128 | $col = 2
129 | $cells.item($row,$col)=$Result.SourceServer
130 | $cells.item($row,$col).font.size=12
131 | $Cells.item($row,$col).Columnwidth = 10
132 | $col ++
133 | $cells.item($row,$col)=$Result.TestServer
134 | $cells.item($row,$col).font.size=12
135 | $Cells.item($row,$col).Columnwidth = 10
136 | $col++
137 | $cells.item($row,$col)=$Result.Database
138 | $cells.item($row,$col).font.size=12
139 | $Cells.item($row,$col).Columnwidth = 10
140 | $col++
141 | $cells.item($row,$col)=$Result.FileExists
142 | $cells.item($row,$col).font.size=12
143 | $Cells.item($row,$col).Columnwidth = 10
144 | if($result.FileExists -eq 'True')
145 | {
146 | $Cells.item($row,$col).Interior.ColorIndex= 10
147 | }
148 | elseif($result.FileExists -eq 'False')
149 | {
150 | $Cells.item($row,$col).Interior.ColorIndex= 3
151 | }
152 | else
153 | {
154 | $Cells.item($row,$col).Interior.ColorIndex= 16
155 | }
156 | $col++
157 | $cells.item($row,$col)=$Result.RestoreResult
158 | $cells.item($row,$col).font.size=12
159 | $Cells.item($row,$col).Columnwidth = 10
160 | if($result.RestoreResult -eq 'Success')
161 | {
162 | $Cells.item($row,$col).Interior.ColorIndex= 10
163 | }
164 | elseif($result.RestoreResult -eq 'Failed')
165 | {
166 | $Cells.item($row,$col).Interior.ColorIndex= 3
167 | }
168 | else
169 | {
170 | $Cells.item($row,$col).Interior.ColorIndex= 16
171 | }
172 | $col++
173 | $cells.item($row,$col)=$Result.DBCCResult
174 | $cells.item($row,$col).font.size=12
175 | $Cells.item($row,$col).Columnwidth = 10
176 | if($result.DBCCResult -eq 'Success')
177 | {
178 | $Cells.item($row,$col).Interior.ColorIndex= 10
179 | }
180 | elseif($result.DBCCResult -eq 'Failed')
181 | {
182 | $Cells.item($row,$col).Interior.ColorIndex= 3
183 | }
184 | else
185 | {
186 | $Cells.item($row,$col).Interior.ColorIndex= 16
187 | }
188 | $col++
189 | $cells.item($row,$col)=$Result.SizeMb
190 | $cells.item($row,$col).font.size=12
191 | $Cells.item($row,$col).Columnwidth = 10
192 | $col++
193 | $cells.item($row,$col)=$Result.BackupTaken
194 | $cells.item($row,$col).font.size=12
195 | $Cells.item($row,$col).Columnwidth = 10
196 | if($result.BackupTaken -gt (Get-Date).AddDays(-7))
197 | {
198 | $Cells.item($row,$col).Interior.ColorIndex= 4
199 | }
200 | else
201 | {
202 | $Cells.item($row,$col).Interior.ColorIndex= 3
203 | }
204 | $col++
205 | $cells.item($row,$col)=$Result.BackupFiles
206 | $cells.item($row,$col).font.size=12
207 | $Cells.item($row,$col).Columnwidth = 10
208 | $row++
209 | }
210 | [void]$ws.cells.entireColumn.Autofit()
211 | ## Add the title after the autofit
212 | $col = 2
213 | $row = 1
214 | $cells.item($row,$col)="This report shows the results of the test backups performed on $TestServer for $Server on $TestDate"
215 | $cells.item($row,$col).font.size=18
216 | $Cells.item($row,$col).Columnwidth = 10
217 | $wb.Saveas($filename)
218 | $xl.quit()
219 |
220 | ## Email the results
221 |
222 | Import-Module dbatools
223 | $TestServer = ''
224 | $Server = 'SQL2016N2'
225 | ## Run the test and save to a variable
226 | $Results = Test-DbaLastBackup -SqlServer $server -Destination $TestServer -MaxMB 5
227 | $to = ''
228 | $smtp = 'smtp.gmail.com'
229 | $port = 587
230 | $cred = Get-Credential
231 | $from = 'Beard@TheBeard.Local'
232 | $subject = 'The Beard Reports on Backup Testing'
233 | $Body = $Results | Format-Table | Out-String
234 | Send-MailMessage -To $to -From $from -Body $Body -Subject $subject -SmtpServer $smtp -Priority High -UseSsl -Port $port -Credential $cred
235 |
236 | ## Add to database
237 |
238 | <# Create table
239 | USE [TestResults]
240 | GO
241 | CREATE TABLE [dbo].[backuptest](
242 | [SourceServer] [nvarchar](250) NULL,
243 | [TestServer] [nvarchar](250) NULL,
244 | [Database] [nvarchar](250) NULL,
245 | [FileExists] [nvarchar](10) NULL,
246 | [RestoreResult] [nvarchar](200) NULL,
247 | [DBCCResult] [nvarchar](200) NULL,
248 | [SizeMB] [int] NULL,
249 | [Backuptaken] [datetime] NULL,
250 | [BackupFiles] [nvarchar](300) NULL
251 | ) ON [PRIMARY]
252 | GO
253 | #>
254 |
255 | Import-Module dbatools
256 | $TestServer = ''
257 | $Server = ''
258 | $servers = '','','','',''
259 | ## Run the test for each server and save to a variable (This uses PowerShell v4 or above code)
260 | $Results = $servers.ForEach{Test-DbaLastBackup -SqlServer $_ -Destination $TestServer -MaxMB 5}
261 | ## Convert to a daatatable.
262 | $DataTable = Out-DbaDataTable -InputObject $Results
263 | ## Write to the database
264 | Write-DbaDataTable -SqlServer $Server -Database TestResults -Schema dbo -Table backuptest -KeepNulls -InputObject $DataTable
--------------------------------------------------------------------------------
/Test SQLPath.ps1:
--------------------------------------------------------------------------------
1 | ## create share
2 |
3 | $FileShareParams=@{
4 | Name='SQLBackups'
5 | Description='The Place for SQL Backups'
6 | SourceVolume=(Get-Volume-DriveLetterD)
7 | FileServerFriendlyName='$BackupServer'
8 | }
9 | New-FileShare @FileShareParams
10 |
11 | ## everyone permissions
12 |
13 | $FileSharePermsParams=@{
14 | Name = 'SQLBackups'
15 | AccessRight = 'Modify'
16 | AccountName = 'Everyone'}
17 | Grant-FileShareAccess @FileSharePermsParams
18 |
19 | ## revoke everyone
20 |
21 | Revoke-FileShareAccess Name SQLBackups AccountName 'Everyone'
22 |
23 | ## perms for sql service accounts
24 |
25 | $FileSharePermsParams = @{
26 | Name = 'SQLBackups'
27 | AccessRight = 'Modify'
28 | AccountName = 'SQL_DBEngine_Service_Accounts'
29 | }
30 | Grant-FileShareAccess @FileSharePermsParams
31 |
32 | ## Deny DBA team
33 |
34 | $BlockFileShareParams = @{
35 | Name = 'SQLBackups'
36 | AccountName = 'SQL_DBAs_The_Cool_Ones'
37 | }
38 | Block-FileShareAccess @BlockFileShareParams
39 |
40 | Get-Help Test-DBASqlPath -Full
41 |
42 | ## Test one instance
43 | Test-DBaSqlPath -SqlServer sql2016n1 -Path \\BackupServer\SQLBackups
44 |
45 | ## check numerous instances
46 |
47 | $SQLServers = (Get-VM -ComputerName $HyperVServer).Where{$_.Name -like '*SQL*'}.Name
48 | foreach($Server in $SQLServers)
49 | {
50 | $Test = Test-dbaSqlPath -SqlServer $Server -Path '\\BackupServer\SQLBackups'
51 | [PSCustomObject]@{
52 | Server = $Server
53 | Result = $Test
54 | }
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/TestConfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "XMLHTML":{
3 | "Path": "c:\\temp\\BackupTests\\" ,
4 | "FileName": "TestResults",
5 | "PesterLocation":"GIT:\\dbatools-scripts-stuttgart",
6 | "Skip":true
7 | },
8 | "BackupShare":{
9 | "BackupShare": "C:\\MSSQL\\Backup" ,
10 | "HyperV": "beardnuc",
11 | "NameSearch":"SQL2016",
12 | "Skip":false
13 |
14 | },
15 | "CollationDatabase": {
16 | "HyperV": "beardnuc",
17 | "NameSearch":"ROB-XPS",
18 | "Skip":true
19 | },
20 | "CollationDatabaseDetailed": {
21 | "HyperV": "beardnuc",
22 | "NameSearch":"SQL2016",
23 | "Skip":true
24 | },
25 | "CollationServer": {
26 | "HyperV": "beardnuc",
27 | "NameSearch":"DAVE",
28 | "Skip":true
29 | },
30 | "IdentityColumn": {
31 | "HyperV": "beardnuc",
32 | "NameSearch":"SQL2016",
33 | "Percent": 90,
34 | "Skip":true
35 | },
36 | "IdentityDatabase": {
37 | "HyperV": "beardnuc",
38 | "NameSearch":"DAVE",
39 | "Percent": 1,
40 | "Skip":true
41 | },
42 | "IdentityServer": {
43 | "HyperV": "beardnuc",
44 | "NameSearch":"SQL2016",
45 | "Percent": 1,
46 | "Skip":false
47 | },
48 | "LastBackup": {
49 | "HyperV": "beardnuc",
50 | "NameSearch":"SQL2016",
51 | "TestServer":"ROB-XPS\\DAVE",
52 | "DaysOld":7,
53 | "Skip":false
54 | },
55 | "DBCCdatabase": {
56 | "HyperV": "beardnuc",
57 | "NameSearch":"SQL2016n3",
58 | "DaysOld":7,
59 | "Skip":true
60 | },
61 | "DBCCServerTime": {
62 | "HyperV": "beardnuc",
63 | "NameSearch":"SQL2016n3",
64 | "DaysOld":7,
65 | "Skip":true
66 | },
67 | "DBCCServer": {
68 | "HyperV": "beardnuc",
69 | "NameSearch":"SQL2016",
70 | "Skip":false
71 | },
72 | "SPN": {
73 | "HyperV": "beardnuc",
74 | "NameSearch":"SQL",
75 | "DomainName":"THEBEARD.Local",
76 | "Skip":true
77 | },
78 | "TempDb": {
79 | "HyperV": "beardnuc",
80 | "NameSearch":"SQL2016",
81 | "DomainName":"THEBEARD.Local",
82 | "Skip118":false,
83 | "SkipNumberofFiles":false,
84 | "SkipFileGrowthPercent":false,
85 | "SkipFilesonC":true,
86 | "SkipFileMaxSize":false,
87 | "Skip":false
88 | },
89 | "Network": {
90 | "HyperV": "beardnuc",
91 | "NameSearch":"SQL",
92 | "DomainName":"THEBEARD.Local",
93 | "Latency":40,
94 | "Skip":false
95 | }
96 | }
--------------------------------------------------------------------------------