├── .vscode └── launch.json ├── LICENSE.txt ├── README.md ├── SQLDiagAPI.psd1 ├── SQLDiagAPI.psm1 ├── appveyor.yml ├── builddocs.ps1 ├── contributing.md ├── docs ├── functions │ ├── Get-SQLDiagAnalysis.md │ ├── Get-SQLDiagAnalysisHistory.md │ ├── Get-SQLDiagDumpFile.md │ ├── Get-SQLDiagFeature.md │ ├── Get-SQLDiagFix.md │ ├── Get-SQLDiagLatestAnalysis.md │ ├── Get-SQLDiagLatestCU.md │ ├── Get-SQLDiagProduct.md │ ├── Get-SQLDiagRecommendations.md │ ├── Get-SQLDiagSupportedRegions.md │ └── Invoke-SQLDiagDumpAnalysis.md └── index.md ├── functions ├── Get-SQLDiagAnalysis.ps1 ├── Get-SQLDiagAnalysisHistory.ps1 ├── Get-SQLDiagDumpFile.ps1 ├── Get-SQLDiagFeature.ps1 ├── Get-SQLDiagFix.ps1 ├── Get-SQLDiagLatestAnalysis.ps1 ├── Get-SQLDiagLatestCU.ps1 ├── Get-SQLDiagProduct.ps1 ├── Get-SQLDiagRecommendations.ps1 ├── Get-SQLDiagSupportedRegions.ps1 └── Invoke-SQLDiagDumpAnalysis.ps1 ├── header-mkdocs.yml ├── install.md ├── install.ps1 ├── internal ├── Get-MachineGuid.ps1 ├── Get-UploadURL.ps1 ├── ShowDialog.ps1 ├── Start-FileAnalysis.ps1 ├── Start-FileUpload.ps1 └── invoke-FilePicker.ps1 ├── mkdocs.yml └── tests ├── Feature.Tests.ps1 ├── Help.Exceptions.ps1 ├── Help.Tests.ps1 ├── Project.Tests.ps1 ├── Regression.Tests.ps1 ├── Unit.Tests.ps1 └── json ├── Features.Json ├── Fix.json ├── LatestCuProductDefault.json ├── ProductFeatures.json └── recommendations.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": "launch", 15 | "name": "PowerShell Launch Current File in Temporary Console", 16 | "script": "${file}", 17 | "args": [], 18 | "cwd": "${file}", 19 | "createTemporaryIntegratedConsole": true 20 | }, 21 | { 22 | "type": "PowerShell", 23 | "request": "launch", 24 | "name": "PowerShell Launch Current File w/Args Prompt", 25 | "script": "${file}", 26 | "args": [ 27 | "${command:SpecifyScriptArgs}" 28 | ], 29 | "cwd": "${file}" 30 | }, 31 | { 32 | "type": "PowerShell", 33 | "request": "attach", 34 | "name": "PowerShell Attach to Host Process", 35 | "processId": "${command:PickPSHostProcess}", 36 | "runspaceId": 1 37 | }, 38 | { 39 | "type": "PowerShell", 40 | "request": "launch", 41 | "name": "PowerShell Interactive Session", 42 | "cwd": "${workspaceRoot}" 43 | } 44 | ] 45 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 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 General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## SQLDiagAPI 2 | 3 | This is a module to work with the SQL Server Diagnostics (Preview) API. See https://blogs.msdn.microsoft.com/sql_server_team/sql-server-diagnostics-preview/ for more details 4 | 5 | Blog Posts about this module 6 | 7 | How the module was created and usign TDD for Get-SQLDiagRecommendations 8 | http://sqldbawithabeard.com/2017/06/30/creating-a-powershell-module-and-tdd-for-get-sqldiagrecommendations/ 9 | 10 | using Get-SQLDiagRecommendations 11 | http://sqldbawithabeard.com/2017/06/29/powershell-module-for-the-sql-server-diagnostics-api-1st-command-get-sqldiagrecommendations/ 12 | 13 | Using Get-SQLDiagFix 14 | https://sqldbawithabeard.com/2017/07/04/using-get-sqldiagfix-to-get-information-from-the-sql-server-diagnostic-api-with-powershell/ 15 | 16 | ## Installation 17 | 18 | Please follow the instructions here [install](install.md) 19 | 20 | ## Commands 21 | 22 | To understand how best to use the commands please run 23 | 24 | Get-Help CommandName -Full 25 | 26 | This will show you details and plenty of examples 27 | 28 | You can also find the documentation for the commands [here](docs) 29 | 30 | ### Get-SQLDiagFix 31 | 32 | [This function](functions\Get-SQLDiagFix.ps1) connects to the SQL Server Diagnostic Recommendations API and returns the Fixes for the latest Cumulative Update by Product or Feature Area or both. 33 | 34 | The video below shows how it works 35 | 36 | [![Alt text](https://img.youtube.com/vi/iaPjG38tnPA/0.jpg)](https://youtu.be/iaPjG38tnPA) 37 | 38 | ### Get-SQLDiagRecommendations 39 | 40 | [This function](functions\Get-SQLDiagRecommendations.ps1) connects to the SQL Server Diagnostic Recommendations API and returns a PSCustomObject 41 | with information about the latest Cumulative Updates for various SQL Server Versions. 42 | Details here https://ecsapi.portal.azure-api.net/ 43 | 44 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 45 | in a file named SQLDiag.Cred 46 | 47 | ![alt text](https://newsqldbawiththebeard.files.wordpress.com/2017/07/get-sqldiagrecommendations-screenshot.png "Get-SQLDiagRecommendations") 48 | 49 | ### Get-SQLDiagProduct 50 | 51 | [This function](functions\Get-SQLDiagProduct.ps1) returns the products available in the SQL Server Diagnostic API 52 | 53 | ![alt text](https://newsqldbawiththebeard.files.wordpress.com/2017/06/screenshot1.png "Get-SQLDiagProduct") 54 | 55 | 56 | ### Get-SQLDiagLatestCU 57 | 58 | [This function](functions\Get-SQLDiagLatestCU.ps1) returns the latest Cumulative Updates and the date 59 | 60 | ![alt text](https://newsqldbawiththebeard.files.wordpress.com/2017/07/get-sqldiaglatestcus-screenshot.png "Get-SQLDiagLatestCU") 61 | 62 | 63 | ### Get-SQLDiagFeature 64 | [This function](functions\Get-SQLDiagFeature.ps1) will show the feature areas that have fixes in the SQL Server Diagnostics Recommendations API for one, several or all products 65 | 66 | ![alt text](https://newsqldbawiththebeard.files.wordpress.com/2017/07/get-sqldiagfeature-screenshot1.png "Get-SQLDiagFeature") 67 | 68 | 69 | Authored by Rob Sewell 70 | 71 | -------------------------------------------------------------------------------- /SQLDiagAPI.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'SQLDiagAPI' 3 | # 4 | # Generated by: Rob Sewell 5 | # 6 | # Generated on: 27/06/2017 7 | # 8 | 9 | @{ 10 | 11 | # Script module or binary module file associated with this manifest. 12 | RootModule = 'SQLDiagAPI.psm1' 13 | 14 | # Version number of this module. 15 | ModuleVersion = '0.9.1' 16 | 17 | # Supported PSEditions 18 | # CompatiblePSEditions = @() 19 | 20 | # ID used to uniquely identify this module 21 | GUID = '38e94bb6-0a1d-4faf-9b1c-10d07727c773' 22 | 23 | # Author of this module 24 | Author = 'Rob Sewell - @SQLDBAWithBeard https://SQLDBAWithABeard.com' 25 | 26 | # Company or vendor of this module 27 | CompanyName = 'Unknown' 28 | 29 | # Copyright statement for this module 30 | Copyright = '(c) 2017 Rob Sewell. All rights reserved. @SQLDBAWithBeard https://SQLDBAWithABeard.com' 31 | 32 | # Description of the functionality provided by this module 33 | Description = 'This is a module to work with the SQL Server Diagnostics (Preview) API. See https://blogs.msdn.microsoft.com/sql_server_team/sql-server-diagnostics-preview/ for more details ' 34 | 35 | # Minimum version of the Windows PowerShell engine required by this module 36 | # PowerShellVersion = '' 37 | 38 | # Name of the Windows PowerShell host required by this module 39 | # PowerShellHostName = '' 40 | 41 | # Minimum version of the Windows PowerShell host required by this module 42 | # PowerShellHostVersion = '' 43 | 44 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 45 | # DotNetFrameworkVersion = '' 46 | 47 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 48 | # CLRVersion = '' 49 | 50 | # Processor architecture (None, X86, Amd64) required by this module 51 | # ProcessorArchitecture = '' 52 | 53 | # Modules that must be imported into the global environment prior to importing this module 54 | # RequiredModules = @() 55 | 56 | # Assemblies that must be loaded prior to importing this module 57 | # RequiredAssemblies = @() 58 | 59 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 60 | # ScriptsToProcess = @() 61 | 62 | # Type files (.ps1xml) to be loaded when importing this module 63 | # TypesToProcess = @() 64 | 65 | # Format files (.ps1xml) to be loaded when importing this module 66 | # FormatsToProcess = @() 67 | 68 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 69 | # NestedModules = @() 70 | 71 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. 72 | FunctionsToExport = @('Get-SQLDiagAnalysis', 73 | 'Get-SQLDiagAnalysisHistory', 74 | 'Get-SQLDiagDumpFile', 75 | 'Get-SQLDiagFeature', 76 | 'Get-SQLDiagFix', 77 | 'Get-SQLDiagLatestAnalysis', 78 | 'Get-SQLDiagLatestCU', 79 | 'Get-SQLDiagProduct', 80 | 'Get-SQLDiagRecommendations', 81 | 'Get-SQLDiagSupportedRegions', 82 | 'Invoke-SQLDiagDumpAnalysis') 83 | 84 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. 85 | CmdletsToExport = @() 86 | 87 | # Variables to export from this module 88 | VariablesToExport = '*' 89 | 90 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. 91 | AliasesToExport = @() 92 | 93 | # DSC resources to export from this module 94 | # DscResourcesToExport = @() 95 | 96 | # List of all modules packaged with this module 97 | # ModuleList = @() 98 | 99 | # List of all files packaged with this module 100 | # FileList = @() 101 | 102 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. 103 | PrivateData = @{ 104 | 105 | PSData = @{ 106 | # The primary categorization of this module (from the TechNet Gallery tech tree). 107 | Category = "Databases" 108 | # Tags applied to this module. These help with module discovery in online galleries. 109 | Tags = @('sqlserver' , 'sql' ,'dba', 'diagnostics', 'SQLDiagAPI') 110 | 111 | # A URL to the license for this module. 112 | LicenseUri = 'https://github.com/SQLDBAWithABeard/SQLDiagAPI/blob/master/LICENSE.txt' 113 | 114 | # A URL to the main website for this project. 115 | ProjectUri = 'https://github.com/SQLDBAWithABeard/SQLDiagAPI/' 116 | 117 | # A URL to an icon representing this module. 118 | # IconUri = '' 119 | 120 | # ReleaseNotes of this module 121 | # ReleaseNotes = '' 122 | 123 | } # End of PSData hashtable 124 | 125 | } # End of PrivateData hashtable 126 | 127 | # HelpInfo URI of this module 128 | HelpInfoURI = 'https://github.com/SQLDBAWithABeard/SQLDiagAPI/tree/master/docs' 129 | 130 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 131 | # DefaultCommandPrefix = '' 132 | 133 | } 134 | 135 | 136 | -------------------------------------------------------------------------------- /SQLDiagAPI.psm1: -------------------------------------------------------------------------------- 1 | [cmdletbinding()] 2 | param() 3 | Write-Verbose $PSScriptRoot 4 | 5 | Write-Verbose 'Import everything in sub folders folder' 6 | 7 | foreach($folder in @('internal', 'functions')) 8 | 9 | { 10 | 11 | $root = Join-Path -Path $PSScriptRoot -ChildPath $folder 12 | 13 | if(Test-Path -Path $root) 14 | 15 | { 16 | 17 | Write-Verbose "processing folder $root" 18 | 19 | $files = Get-ChildItem -Path $root -Filter *.ps1 -Recurse 20 | 21 | 22 | 23 | # dot source each file 24 | 25 | $files | where-Object{ $_.name -NotLike '*.Tests.ps1'} | 26 | 27 | ForEach-Object{Write-Verbose $_.basename; . $_.FullName} 28 | 29 | } 30 | 31 | } 32 | 33 | 34 | 35 | Export-ModuleMember -function (Get-ChildItem -Path "$PSScriptRoot\functions\*.ps1").basename -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLDBAWithABeard/SQLDiagAPI/4dd237276351e3175bd13352063b0c5444ba4b3b/appveyor.yml -------------------------------------------------------------------------------- /builddocs.ps1: -------------------------------------------------------------------------------- 1 | $ProjectRoot = Get-Location 2 | $ModuleName = 'SQLDiagAPI' 3 | $BuildDate = Get-Date -uFormat '%Y-%m-%d' 4 | $ReleaseNotes = "$ProjectRoot\RELEASE.md" 5 | $ChangeLog = "$ProjectRoot\docs\ChangeLog.md" 6 | 7 | 8 | #Build YAMLText starting with the header 9 | $YMLtext = (Get-Content "$ProjectRoot\header-mkdocs.yml") -join "`n" 10 | $YMLtext = "$YMLtext`n" 11 | 12 | $parameters = @{ 13 | Path = $ReleaseNotes 14 | ErrorAction = 'SilentlyContinue' 15 | } 16 | $ReleaseText = (Get-Content @parameters) -join "`n" 17 | if ($ReleaseText) { 18 | $ReleaseText | Set-Content "$ProjectRoot\docs\RELEASE.md" 19 | $YMLText = "$YMLtext - Realse Notes: RELEASE.md`n" 20 | } 21 | if ((Test-Path -Path $ChangeLog)) { 22 | $YMLText = "$YMLtext - Change Log: ChangeLog.md`n" 23 | } 24 | $YMLText = "$YMLtext - Functions:`n" 25 | 26 | $Params = @{ 27 | Module = 'SQLDiagAPI' 28 | Force = $true 29 | OutputFolder = "$ProjectRoot\docs\functions" 30 | NoMetadata = $true 31 | } 32 | New-MarkdownHelp @Params | foreach-object { 33 | $Function = $_.Name -replace '\.md', '' 34 | $Part = " - {0}: functions/{1}" -f $Function, $_.Name 35 | $YMLText = "{0}{1}`n" -f $YMLText, $Part 36 | $Part 37 | } 38 | $YMLtext | Set-Content -Path "$ProjectRoot\mkdocs.yml" -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing.md 2 | This is the contribute.md of our project. 3 | 4 | Great to have you here! 5 | 6 | You are welcome to fork this repository do some work and create a pull request. If you do not know how to do this do not worry. Chrissy LeMaire has written an [excellent guide](https://github.com/sqlcollaborative/dbatools/wiki/Your-First-Pull-Request) and even a [video](https://www.youtube.com/watch?v=-OJdRhfV4Xg) to show you the steps to take 7 | 8 | I highly recommend that you use visual Studio Code to develop this module 9 | 10 | For the SQLDiagAPI module there are a number of Pester Tests. To understand how the module was created and the steps that I have taken to develop the initial commands you can read my [blog post](http://sqldbawithabeard.com/2017/06/30/creating-a-powershell-module-and-tdd-for-get-sqldiagrecommendations/) 11 | 12 | In simple terms if you are writing a new command you should edit the [Unit.Tests.ps1](functions\Unit.Tests.ps1) file and add the scaffolding for the tests for the new command. You can copy and paste from existing commands. 13 | 14 | You can see examples in that file of mocking other commands and asserting that the mocks have been called 15 | 16 | The tests\json folder has a number of json files which are used to validate the results of the code without needing to be online 17 | 18 | When writing code I will write a test and then from the root of the module run 19 | 20 | Invoke-Pester .\tests -Show Fails -Tag Unit 21 | 22 | This will only run the tests that are tagged Unit (the ones in the Unit.Tests.ps1 file) and only display to the screen the Describe and Context titles and the failed tests. If you want to see all of the test results you can remove the -Show Fails but this will take longer to run 23 | 24 | I will then write the code to pass the tests. The commit history will show this process in action 25 | 26 | Repeat that until the command has been written and then run 27 | 28 | Invoke-Pester .\tests -Show Fails -Tag ScriptAnalyzer 29 | 30 | this will run the tests tagged ScriptAnalyzer in the Project.Tests.ps1 file to check that the code follows best guidelines according to the Script Analyzer Rules. If you want to see all of the test results you can remove the -Show Fails but this will take longer to run. If you get errors you can run 31 | 32 | Invoke-ScriptAnalyzer -Path PATHTOSCRIPTFILE 33 | 34 | which will give you more information about the reason for the failure and the line numbers 35 | 36 | Once that has passed then I run 37 | 38 | Invoke-Pester .\tests -Tag Help -Show Fails 39 | 40 | To run the tests to see if the help is correct for the functions.If you want to see all of the test results you can remove the -Show Fails but this will take longer to run. 41 | 42 | Good help should include plenty of detailed examples. You can easily add help in Visual Studio Code. See [this blog post](https://sqldbawithabeard.com/2017/06/12/vs-code-automatic-dynamic-powershell-help/) for instructions 43 | 44 | Then I run 45 | 46 | Invoke-Pester .\tests -Tag Help -Show Fails 47 | 48 | and then sync the repository -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagAnalysis.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagAnalysis 2 | 3 | ## SYNOPSIS 4 | Returns the detail of an analysis from the SQL Server Diagnostics API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagAnalysis [-APIKey ] [-RequestID] [-WhatIf] [-Confirm] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Connects to the SQL Server Diagnostics API and returns the details of a 14 | single analysis 15 | 16 | ## EXAMPLES 17 | 18 | ### EXAMPLE 1 19 | ``` 20 | Get-SQLDiagAnalysis -RequestID 4b36a572-3925-4f7f-8f5a-bf964582b986 21 | ``` 22 | 23 | Returns the Diagnosis analysis for the request id specified 24 | 25 | ### EXAMPLE 2 26 | ``` 27 | Get-SQLDiagAnalysisHistory -Since Yesterday | Out-GridView -PassThru | Get-SQLDiagAnalysis 28 | ``` 29 | 30 | Gets the Diagnosis history, displays it in Out-GridView and then gets the analysis for the 31 | chosen request 32 | 33 | ## PARAMETERS 34 | 35 | ### -APIKey 36 | The APIKey used to authenticate against the API. 37 | You can get one from https://ecsapi.portal.azure-api.net/ 38 | 39 | ```yaml 40 | Type: String 41 | Parameter Sets: (All) 42 | Aliases: 43 | 44 | Required: False 45 | Position: Named 46 | Default value: None 47 | Accept pipeline input: False 48 | Accept wildcard characters: False 49 | ``` 50 | 51 | ### -RequestID 52 | The request ID for analysis - You can get this from Get-SQLDiagHistory 53 | 54 | ```yaml 55 | Type: String 56 | Parameter Sets: (All) 57 | Aliases: 58 | 59 | Required: True 60 | Position: 1 61 | Default value: None 62 | Accept pipeline input: True (ByPropertyName, ByValue) 63 | Accept wildcard characters: False 64 | ``` 65 | 66 | ### -WhatIf 67 | Shows what would happen if the cmdlet runs. 68 | The cmdlet is not run. 69 | 70 | ```yaml 71 | Type: SwitchParameter 72 | Parameter Sets: (All) 73 | Aliases: wi 74 | 75 | Required: False 76 | Position: Named 77 | Default value: None 78 | Accept pipeline input: False 79 | Accept wildcard characters: False 80 | ``` 81 | 82 | ### -Confirm 83 | Prompts you for confirmation before running the cmdlet. 84 | 85 | ```yaml 86 | Type: SwitchParameter 87 | Parameter Sets: (All) 88 | Aliases: cf 89 | 90 | Required: False 91 | Position: Named 92 | Default value: None 93 | Accept pipeline input: False 94 | Accept wildcard characters: False 95 | ``` 96 | 97 | ### CommonParameters 98 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 99 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 100 | 101 | ## INPUTS 102 | 103 | ## OUTPUTS 104 | 105 | ## NOTES 106 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 107 | DATE 11/07/2017 108 | 109 | ## RELATED LINKS 110 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagAnalysisHistory.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagAnalysisHistory 2 | 3 | ## SYNOPSIS 4 | Returns the SQL Server dump file diagnosis history for this machine from the 5 | SQL Server Diagnostics API 6 | 7 | ## SYNTAX 8 | 9 | ``` 10 | Get-SQLDiagAnalysisHistory [[-Status] ] [[-Since] ] [[-APIKey] ] [-WhatIf] [-Confirm] 11 | [] 12 | ``` 13 | 14 | ## DESCRIPTION 15 | Returns the SQL Server dump file diagnosis history for this machine from the 16 | SQL Server Diagnostics API 17 | Details here https://ecsapi.portal.azure-api.net/ 18 | 19 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 20 | in a file named SQLDiag.Cred 21 | 22 | ## EXAMPLES 23 | 24 | ### EXAMPLE 1 25 | ``` 26 | Get-SQLDiagAnalysisHistory 27 | ``` 28 | 29 | Returns the SQL Server dump file diagnosis history for this machine from the 30 | SQL Server Diagnostics API 31 | 32 | ### EXAMPLE 2 33 | ``` 34 | Get-SQLDiagAnalysisHistory -Status Complete 35 | ``` 36 | 37 | Returns the SQL Server dump file diagnosis history for completed dump Analysis for this machine from the 38 | SQL Server Diagnostics API 39 | 40 | ### EXAMPLE 3 41 | ``` 42 | Get-SQLDiagAnalysisHistory -Status Failed 43 | ``` 44 | 45 | Returns the SQL Server dump file diagnosis history for dump Analysis that have failed for this machine from the 46 | SQL Server Diagnostics API 47 | 48 | ### EXAMPLE 4 49 | ``` 50 | Get-SQLDiagAnalysisHistory -Status 'In Progress' 51 | ``` 52 | 53 | Returns the SQL Server dump file diagnosis history for dump Analysis that are in progress for this machine from the 54 | SQL Server Diagnostics API 55 | 56 | ### EXAMPLE 5 57 | ``` 58 | Get-SQLDiagAnalysisHistory -Since Today 59 | ``` 60 | 61 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight today for this machine from the 62 | SQL Server Diagnostics API 63 | 64 | ### EXAMPLE 6 65 | ``` 66 | Get-SQLDiagAnalysisHistory -Since Yesterday 67 | ``` 68 | 69 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight Yesterday for this machine from the 70 | SQL Server Diagnostics API 71 | 72 | ### EXAMPLE 7 73 | ``` 74 | Get-SQLDiagAnalysisHistory -Since 'This Week' 75 | ``` 76 | 77 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight on Monday morning of this week for 78 | this machine from the SQL Server Diagnostics API 79 | 80 | ### EXAMPLE 8 81 | ``` 82 | Get-SQLDiagAnalysisHistory -Since 'This Month' 83 | ``` 84 | 85 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight on the 1st of this month for 86 | this machine from the SQL Server Diagnostics API 87 | 88 | ## PARAMETERS 89 | 90 | ### -Status 91 | Status of the request - accepted values are Complete, Failed, In Progress 92 | 93 | ```yaml 94 | Type: String 95 | Parameter Sets: (All) 96 | Aliases: 97 | 98 | Required: False 99 | Position: 1 100 | Default value: None 101 | Accept pipeline input: False 102 | Accept wildcard characters: False 103 | ``` 104 | 105 | ### -Since 106 | Time paramater to filter the history - accepted values 'Today', 'Yesterday', 'This Week', 'This Month' 107 | 108 | ```yaml 109 | Type: Object 110 | Parameter Sets: (All) 111 | Aliases: 112 | 113 | Required: False 114 | Position: 2 115 | Default value: None 116 | Accept pipeline input: False 117 | Accept wildcard characters: False 118 | ``` 119 | 120 | ### -APIKey 121 | The APIKey used to authenticate against the API. 122 | You can get one from https://ecsapi.portal.azure-api.net/ 123 | 124 | ```yaml 125 | Type: Object 126 | Parameter Sets: (All) 127 | Aliases: 128 | 129 | Required: False 130 | Position: 3 131 | Default value: None 132 | Accept pipeline input: False 133 | Accept wildcard characters: False 134 | ``` 135 | 136 | ### -WhatIf 137 | Shows what would happen if the cmdlet runs. 138 | The cmdlet is not run. 139 | 140 | ```yaml 141 | Type: SwitchParameter 142 | Parameter Sets: (All) 143 | Aliases: wi 144 | 145 | Required: False 146 | Position: Named 147 | Default value: None 148 | Accept pipeline input: False 149 | Accept wildcard characters: False 150 | ``` 151 | 152 | ### -Confirm 153 | Prompts you for confirmation before running the cmdlet. 154 | 155 | ```yaml 156 | Type: SwitchParameter 157 | Parameter Sets: (All) 158 | Aliases: cf 159 | 160 | Required: False 161 | Position: Named 162 | Default value: None 163 | Accept pipeline input: False 164 | Accept wildcard characters: False 165 | ``` 166 | 167 | ### CommonParameters 168 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 169 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 170 | 171 | ## INPUTS 172 | 173 | ## OUTPUTS 174 | 175 | ## NOTES 176 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 177 | DATE 28/06/2017 178 | 179 | ## RELATED LINKS 180 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagDumpFile.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagDumpFile 2 | 3 | ## SYNOPSIS 4 | Gets a SQL Server Dump File for uploading to the API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagDumpFile [[-file] ] [-WhatIf] [-Confirm] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Gets a SQL Server Dump File for uploading to the API. 14 | Opens a graphical file picker if no file specified 15 | 16 | ## EXAMPLES 17 | 18 | ### EXAMPLE 1 19 | ``` 20 | Get-SQLDiagDumpFile | Invoke-SQLDiagDumpAnalysis -Region 'West US' -Email a@a.com 21 | ``` 22 | 23 | opens a file picker to choose a file which is then uploaded to teh West US Azure region 24 | and analysed with the SQL Server Diagnostic API 25 | 26 | ## PARAMETERS 27 | 28 | ### -file 29 | Path to file 30 | 31 | ```yaml 32 | Type: String 33 | Parameter Sets: (All) 34 | Aliases: 35 | 36 | Required: False 37 | Position: 1 38 | Default value: None 39 | Accept pipeline input: True (ByPropertyName) 40 | Accept wildcard characters: False 41 | ``` 42 | 43 | ### -WhatIf 44 | Shows what would happen if the cmdlet runs. 45 | The cmdlet is not run. 46 | 47 | ```yaml 48 | Type: SwitchParameter 49 | Parameter Sets: (All) 50 | Aliases: wi 51 | 52 | Required: False 53 | Position: Named 54 | Default value: None 55 | Accept pipeline input: False 56 | Accept wildcard characters: False 57 | ``` 58 | 59 | ### -Confirm 60 | Prompts you for confirmation before running the cmdlet. 61 | 62 | ```yaml 63 | Type: SwitchParameter 64 | Parameter Sets: (All) 65 | Aliases: cf 66 | 67 | Required: False 68 | Position: Named 69 | Default value: None 70 | Accept pipeline input: False 71 | Accept wildcard characters: False 72 | ``` 73 | 74 | ### CommonParameters 75 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 76 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 77 | 78 | ## INPUTS 79 | 80 | ## OUTPUTS 81 | 82 | ## NOTES 83 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 84 | DATE 07/07/2017 85 | 86 | ## RELATED LINKS 87 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagFeature.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagFeature 2 | 3 | ## SYNOPSIS 4 | Returns the Features avaialble from teh SQL Server Diagnostic Recommendations API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagFeature [-Recommendations ] [-Product ] [[-Feature] ] 10 | [] 11 | ``` 12 | 13 | ## DESCRIPTION 14 | This will connect to to the SQL Server Diagnostic Recommendations API and return the 15 | unique list of features for some or all of the Products 16 | 17 | ## EXAMPLES 18 | 19 | ### EXAMPLE 1 20 | ``` 21 | Get-SQLDiagFeature 22 | ``` 23 | 24 | This will return a unique list of all of the Feature Areas that have fixes from the SQL Server Diagnostic API 25 | 26 | ### EXAMPLE 2 27 | ``` 28 | Get-SQLDiagFeature -Feature Always 29 | ``` 30 | 31 | This will return a unique list of all of the Feature Areas that have fixes from the SQL Server Diagnostic API 32 | with a name including Always (case insensitive) 33 | 34 | ### EXAMPLE 3 35 | ``` 36 | Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' 37 | ``` 38 | 39 | This will return a unique list of all of the Feature Areas that have fixes for the product SQL Server 2012 SP3 40 | from the SQL Server Diagnostic API 41 | 42 | ### EXAMPLE 4 43 | ``` 44 | Get-SQLDiagProduct 2016 | Get-SQLDiagFeature 45 | ``` 46 | 47 | This will return a unique list of all of the Feature Areas that have fixes for products with 2016 in the name 48 | from the SQL Server Diagnostic API 49 | 50 | ### EXAMPLE 5 51 | ``` 52 | Get-SQLDiagProduct 2016 | Get-SQLDiagFeature Always 53 | ``` 54 | 55 | This will return a unique list of all of the Feature Areas that have fixes for products with 2016 in the name 56 | and features with Always in the name (case insensitive) from the SQL Server Diagnostic API 57 | 58 | ## PARAMETERS 59 | 60 | ### -Recommendations 61 | The recommendation object from the API - Use Get-SQLDiagRecommendations by default 62 | 63 | ```yaml 64 | Type: PSObject 65 | Parameter Sets: (All) 66 | Aliases: 67 | 68 | Required: False 69 | Position: Named 70 | Default value: (Get-SQLDiagRecommendations) 71 | Accept pipeline input: True (ByPropertyName) 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -Product 76 | The product or products that you want to filter by Get-SQLDiagProduct will show the options 77 | 78 | ```yaml 79 | Type: Object[] 80 | Parameter Sets: (All) 81 | Aliases: 82 | 83 | Required: False 84 | Position: Named 85 | Default value: None 86 | Accept pipeline input: True (ByPropertyName, ByValue) 87 | Accept wildcard characters: False 88 | ``` 89 | 90 | ### -Feature 91 | Wildcard case insensitive search for feature name 92 | 93 | ```yaml 94 | Type: String[] 95 | Parameter Sets: (All) 96 | Aliases: 97 | 98 | Required: False 99 | Position: 1 100 | Default value: None 101 | Accept pipeline input: False 102 | Accept wildcard characters: False 103 | ``` 104 | 105 | ### CommonParameters 106 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 107 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 108 | 109 | ## INPUTS 110 | 111 | ## OUTPUTS 112 | 113 | ## NOTES 114 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 115 | DATE 30/06/2017 116 | 117 | ## RELATED LINKS 118 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagFix.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagFix 2 | 3 | ## SYNOPSIS 4 | Returns the Fixes from the SQL Server Diagnostic recommnendations API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagFix [-Recommendations ] [-Product ] [[-Feature] ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for the 14 | Fixes in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 15 | 16 | ## EXAMPLES 17 | 18 | ### EXAMPLE 1 19 | ``` 20 | Get-SQLDiagFix 21 | ``` 22 | 23 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the 24 | Fixes in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 25 | 26 | ### EXAMPLE 2 27 | ``` 28 | Get-SQLDiagFix -Product 'SQL Server 2012 SP3' 29 | ``` 30 | 31 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for 32 | SQL Server 2012 SP3 in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 33 | 34 | ### EXAMPLE 3 35 | ``` 36 | Get-SQLDiagFix -Feature 'Always On' 37 | ``` 38 | 39 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 40 | Feature Area Always On in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 41 | 42 | ### EXAMPLE 4 43 | ``` 44 | Get-SQLDiagFix 'Always On' 45 | ``` 46 | 47 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 48 | Feature Area Always On in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 49 | 50 | ### EXAMPLE 5 51 | ``` 52 | Get-SQLDiagFix -Product 'SQL Server 2012 SP3' -Feature 'Always On' 53 | ``` 54 | 55 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 56 | Feature Area Always On for SQL Server 2012 SP3 in the Cumulative Updates returned from the SQL Server 57 | Diagnostics Recommendations API 58 | 59 | ### EXAMPLE 6 60 | ``` 61 | Get-SQLDiagProduct 2012 | Get-SQLDiagFix 62 | ``` 63 | 64 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 65 | Feature Area Always On for products with 2012 in the name in the Cumulative Updates returned from 66 | the SQL Server Diagnostics Recommendations API 67 | 68 | ### EXAMPLE 7 69 | ``` 70 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix 71 | ``` 72 | 73 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 74 | Feature Area Always On for products with SP1 in the name in the Cumulative Updates returned from 75 | the SQL Server Diagnostics Recommendations API 76 | 77 | ### EXAMPLE 8 78 | ``` 79 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix -Feature (Get-SQLDiagFeature -Feature AL) 80 | ``` 81 | 82 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 83 | Feature Areas with AL in the name for products with SP1 in the name in the Cumulative Updates returned 84 | from the SQL Server Diagnostics Recommendations API 85 | 86 | ### EXAMPLE 9 87 | ``` 88 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix -Feature (Get-SQLDiagFeature -Feature AL) | Out-GridView 89 | ``` 90 | 91 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 92 | Feature Areas with AL in the name for products with SP1 in the name in the Cumulative Updates returned 93 | from the SQL Server Diagnostics Recommendations API and displays them in Out-GridView 94 | 95 | ### EXAMPLE 10 96 | ``` 97 | Get-SQLDiagFix | Export-Csv -Path C:\temp\Fixes.csv 98 | ``` 99 | 100 | Exports the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes in the 101 | Cumulative Updates returned from the SQL Server Diagnostics Recommendations API into a File 102 | 103 | ### EXAMPLE 11 104 | ``` 105 | $Fixes = Get-SQLDiagFix | Out-DbaDataTable 106 | ``` 107 | 108 | Write-DbaDataTable -SqlServer $Server -Database $DB -InputObject $Fixes-Table Fixes -AutoCreateTable 109 | 110 | Puts the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes in the 111 | Cumulative Updates returned from the SQL Server Diagnostics Recommendations API into a 112 | database table and creates the table - Requires dbatools https://dbatools.io 113 | 114 | ### EXAMPLE 12 115 | ``` 116 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix -Feature (Get-SQLDiagFeature -Feature AL) | Out-GridView -PassThru | ForEach-Object {Start-Process $_.UR} 117 | ``` 118 | 119 | Opens the URL for a Fix that the user chooses from Out-GridView which is populated with all of the Fixes for the 120 | Feature Areas with AL in the name for products with SP1 in the name in the Cumulative Updates returned 121 | from the SQL Server Diagnostics Recommendations API 122 | 123 | ## PARAMETERS 124 | 125 | ### -Recommendations 126 | The recommendation object from the API - Uses Get-SQLDiagRecommendations by default 127 | 128 | ```yaml 129 | Type: PSObject 130 | Parameter Sets: (All) 131 | Aliases: 132 | 133 | Required: False 134 | Position: Named 135 | Default value: (Get-SQLDiagRecommendations) 136 | Accept pipeline input: True (ByPropertyName) 137 | Accept wildcard characters: False 138 | ``` 139 | 140 | ### -Product 141 | The product or products that you want to filter by Get-SQLDiagProduct will show the options 142 | 143 | ```yaml 144 | Type: Object[] 145 | Parameter Sets: (All) 146 | Aliases: 147 | 148 | Required: False 149 | Position: Named 150 | Default value: None 151 | Accept pipeline input: True (ByPropertyName, ByValue) 152 | Accept wildcard characters: False 153 | ``` 154 | 155 | ### -Feature 156 | The Feature Name or Area that you want to filter by Get-SQLDiagFeature will show the options 157 | 158 | ```yaml 159 | Type: String[] 160 | Parameter Sets: (All) 161 | Aliases: 162 | 163 | Required: False 164 | Position: 1 165 | Default value: None 166 | Accept pipeline input: False 167 | Accept wildcard characters: False 168 | ``` 169 | 170 | ### CommonParameters 171 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 172 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 173 | 174 | ## INPUTS 175 | 176 | ## OUTPUTS 177 | 178 | ## NOTES 179 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 180 | DATE 03/07/2017 181 | 182 | ## RELATED LINKS 183 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagLatestAnalysis.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagLatestAnalysis 2 | 3 | ## SYNOPSIS 4 | Returns information about the latest diagnosis from the SQL Server Diagnostic API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagLatestAnalysis 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Returns information about the latest diagnosis from the SQL Server Diagnostic API 14 | 15 | ## EXAMPLES 16 | 17 | ### EXAMPLE 1 18 | ``` 19 | Get-SQLDiagLatestAnalysis 20 | ``` 21 | 22 | Returns information about the latest diagnosis from the SQL Server Diagnostic API 23 | 24 | ## PARAMETERS 25 | 26 | ## INPUTS 27 | 28 | ## OUTPUTS 29 | 30 | ## NOTES 31 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 32 | DATE 11/07/2017 33 | 34 | ## RELATED LINKS 35 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagLatestCU.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagLatestCU 2 | 3 | ## SYNOPSIS 4 | Gets The Latest Cumulative Updates and Date from the SQL Server Diagnostic API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagLatestCU [-Recommendations ] [[-Product] ] [-LearnMore] [-Download] [-WhatIf] 10 | [-Confirm] [] 11 | ``` 12 | 13 | ## DESCRIPTION 14 | Returns Product Name, Cumulative Update Name and Date created from the SQL Server Diagnostic API 15 | Opens the Learn More webpage with the LearnMore switch 16 | Downloads the CU with the Download Switch 17 | 18 | ## EXAMPLES 19 | 20 | ### EXAMPLE 1 21 | ``` 22 | Get-SQLDiagLatestCU 23 | ``` 24 | 25 | Returns Product Name, Cumulative Update Name and Date created for all products from the SQL Server Diagnostic API 26 | 27 | ### EXAMPLE 2 28 | ``` 29 | Get-SQLDiagRecommendations | Get-SQLDiagLatestCU 30 | ``` 31 | 32 | Returns Product Name, Cumulative Update Name and Date created for all products from the SQL Server Diagnostic API 33 | 34 | ### EXAMPLE 3 35 | ``` 36 | Get-SQLDiagLatestCU -Recommendations (Get-SQLDiagRecommendations) 37 | ``` 38 | 39 | Returns Product Name, Cumulative Update Name and Date created for all products from the SQL Server Diagnostic API 40 | 41 | ### EXAMPLE 4 42 | ``` 43 | Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU 44 | ``` 45 | 46 | Returns Product Name, Cumulative Update Name and Date created for products named 2012 from the SQL Server Diagnostic API 47 | 48 | ### EXAMPLE 5 49 | ``` 50 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' 51 | ``` 52 | 53 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 from the SQL Server Diagnostic API 54 | 55 | ### EXAMPLE 6 56 | ``` 57 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3','SQL Server 2014 SP1' 58 | ``` 59 | 60 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 and SQL Server 2014 SP1 from the 61 | SQL Server Diagnostic API 62 | 63 | ### EXAMPLE 7 64 | ``` 65 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' -LearnMore 66 | ``` 67 | 68 | Opens the Cumulative Update for SQL Server 2012 SP3 information webpage in the default browser 69 | 70 | ### EXAMPLE 8 71 | ``` 72 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' -Download 73 | ``` 74 | 75 | Opens the Cumulative Update for SQL Server 2012 SP3 download webpage in the default browser 76 | 77 | ### EXAMPLE 9 78 | ``` 79 | Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU -LearnMore 80 | ``` 81 | 82 | Opens the Cumulative Update for SQL Server 2012 SP3 information webpage in the default browser 83 | 84 | ### EXAMPLE 10 85 | ``` 86 | Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU -Download 87 | ``` 88 | 89 | Opens the Cumulative Update for SQL Server 2012 SP3 download webpage in the default browser 90 | 91 | ### EXAMPLE 11 92 | ``` 93 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3','SQL Server 2014 SP1' | Out-GridView 94 | ``` 95 | 96 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 and SQL Server 2014 SP1 from the 97 | SQL Server Diagnostic API and outputs to Out-GridView 98 | 99 | ### EXAMPLE 12 100 | ``` 101 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3','SQL Server 2014 SP1' | Out-File C:\Temp\LatestCU.txt 102 | ``` 103 | 104 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 and SQL Server 2014 SP1 from the 105 | SQL Server Diagnostic API and outputs to a File C:\Temp\LatestCU.txt 106 | 107 | ### EXAMPLE 13 108 | ``` 109 | $LatestCu = Get-SQLDiagLatestCU | Out-DbaDataTable 110 | ``` 111 | 112 | Write-DbaDataTable -SqlServer $Server -Database $DB -InputObject $LatestCu-Table $LatestCu -AutoCreateTable 113 | 114 | Puts Product Name, Cumulative Update Name and Date created for all products from the 115 | SQL Server Diagnostic API into a database table and creates the table - Requires dbatools https://dbatools.io 116 | 117 | ## PARAMETERS 118 | 119 | ### -Recommendations 120 | The recommendation object from the API - Use Get-SQLDiagRecommendations by default 121 | 122 | ```yaml 123 | Type: PSObject 124 | Parameter Sets: (All) 125 | Aliases: 126 | 127 | Required: False 128 | Position: Named 129 | Default value: (Get-SQLDiagRecommendations) 130 | Accept pipeline input: True (ByPropertyName) 131 | Accept wildcard characters: False 132 | ``` 133 | 134 | ### -Product 135 | The product or products that you want to filter by Get-SQLDiagProduct will show the options 136 | 137 | ```yaml 138 | Type: String[] 139 | Parameter Sets: (All) 140 | Aliases: 141 | 142 | Required: False 143 | Position: 1 144 | Default value: None 145 | Accept pipeline input: True (ByValue) 146 | Accept wildcard characters: False 147 | ``` 148 | 149 | ### -LearnMore 150 | Opens the Information web-page for the Cumulative Update for the product specified in the default browser 151 | 152 | ```yaml 153 | Type: SwitchParameter 154 | Parameter Sets: (All) 155 | Aliases: 156 | 157 | Required: False 158 | Position: Named 159 | Default value: False 160 | Accept pipeline input: False 161 | Accept wildcard characters: False 162 | ``` 163 | 164 | ### -Download 165 | Opens the Download page for the Cumulative Update for the product specified in the default browser 166 | 167 | ```yaml 168 | Type: SwitchParameter 169 | Parameter Sets: (All) 170 | Aliases: 171 | 172 | Required: False 173 | Position: Named 174 | Default value: False 175 | Accept pipeline input: False 176 | Accept wildcard characters: False 177 | ``` 178 | 179 | ### -WhatIf 180 | Shows what would happen if the cmdlet runs. 181 | The cmdlet is not run. 182 | 183 | ```yaml 184 | Type: SwitchParameter 185 | Parameter Sets: (All) 186 | Aliases: wi 187 | 188 | Required: False 189 | Position: Named 190 | Default value: None 191 | Accept pipeline input: False 192 | Accept wildcard characters: False 193 | ``` 194 | 195 | ### -Confirm 196 | Prompts you for confirmation before running the cmdlet. 197 | 198 | ```yaml 199 | Type: SwitchParameter 200 | Parameter Sets: (All) 201 | Aliases: cf 202 | 203 | Required: False 204 | Position: Named 205 | Default value: None 206 | Accept pipeline input: False 207 | Accept wildcard characters: False 208 | ``` 209 | 210 | ### CommonParameters 211 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 212 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 213 | 214 | ## INPUTS 215 | 216 | ## OUTPUTS 217 | 218 | ## NOTES 219 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 220 | DATE 30/06/2017 221 | 222 | ## RELATED LINKS 223 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagProduct.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagProduct 2 | 3 | ## SYNOPSIS 4 | Returns the Products avaiable in the SQL Server Diagnostic API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagProduct [-Recommendations ] [[-Product] ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Enables you to search for the products that are available in the SQL Server Diagnostic API 14 | 15 | ## EXAMPLES 16 | 17 | ### EXAMPLE 1 18 | ``` 19 | Get-SQLDiagProduct 20 | ``` 21 | 22 | Returns all of the Product Names in the SQL Server Diagnostic API 23 | 24 | ### EXAMPLE 2 25 | ``` 26 | Get-SQLDiagRecommendations | Get-SQLDiagProduct 27 | ``` 28 | 29 | Returns all of the Product Names in the SQL Server Diagnostic API 30 | 31 | ### EXAMPLE 3 32 | ``` 33 | Get-SQLDiagProduct -Product 2012 34 | ``` 35 | 36 | Returns all of the Product Names in the SQL Server Diagnostic API with 2012 in the name 37 | 38 | ### EXAMPLE 4 39 | ``` 40 | Get-SQLDiagProduct -Product SP1 41 | ``` 42 | 43 | Returns all of the Product Names in the SQL Server Diagnostic API with SP1 in the name 44 | 45 | ### EXAMPLE 5 46 | ``` 47 | Get-SQLDiagProduct SP1 48 | ``` 49 | 50 | Returns all of the Product Names in the SQL Server Diagnostic API with SP1 in the name 51 | 52 | ### EXAMPLE 6 53 | ``` 54 | $product = Get-SQLDiagProduct -Product 2016 55 | ``` 56 | 57 | Get-SQLDiagLatestCU -Product $product 58 | 59 | Returns Product Name, Cumulative Update Name and Date created for products with 2016 in the name from the 60 | SQL Server Diagnostic API 61 | 62 | ## PARAMETERS 63 | 64 | ### -Recommendations 65 | The recommendation object from the API - Uses Get-SQLDiagRecommendations by default 66 | 67 | ```yaml 68 | Type: PSObject 69 | Parameter Sets: (All) 70 | Aliases: 71 | 72 | Required: False 73 | Position: Named 74 | Default value: (Get-SQLDiagRecommendations) 75 | Accept pipeline input: True (ByPropertyName, ByValue) 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### -Product 80 | The search for the product you do not need to enter wildcards 81 | 82 | ```yaml 83 | Type: String 84 | Parameter Sets: (All) 85 | Aliases: 86 | 87 | Required: False 88 | Position: 1 89 | Default value: None 90 | Accept pipeline input: True (ByPropertyName, ByValue) 91 | Accept wildcard characters: False 92 | ``` 93 | 94 | ### CommonParameters 95 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 96 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 97 | 98 | ## INPUTS 99 | 100 | ## OUTPUTS 101 | 102 | ## NOTES 103 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 104 | DATE 30/06/2017 105 | 106 | ## RELATED LINKS 107 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagRecommendations.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagRecommendations 2 | 3 | ## SYNOPSIS 4 | Uses the SQL Server Diagnostic Recommendations API to return latest CU information as an object 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagRecommendations [[-ApiKey] ] [-WhatIf] [-Confirm] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | This function connects to the SQL Server Diagnostic Recommendations API and returns a PSCustomObject 14 | with information about the latest Cumulative Updates for various SQL Server Versions. 15 | Details here https://ecsapi.portal.azure-api.net/ 16 | 17 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 18 | in a file named SQLDiag.Cred 19 | 20 | ## EXAMPLES 21 | 22 | ### EXAMPLE 1 23 | ``` 24 | Get-SQLDiagRecommendations 25 | ``` 26 | 27 | Returns an object containing the information about the latest CUs for SQL Server using an API Key stored in 28 | the users profile in a file named SQLDiag.Cred 29 | 30 | ### EXAMPLE 2 31 | ``` 32 | $APIKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' 33 | ``` 34 | 35 | Get-SQLDiagRecommendations -ApiKey $APIKey 36 | 37 | Returns an object containing the information about the latest CUs for SQL Server 38 | 39 | ## PARAMETERS 40 | 41 | ### -ApiKey 42 | The APIKey used to authenticate against the API. 43 | You can get one from https://ecsapi.portal.azure-api.net/ 44 | 45 | ```yaml 46 | Type: String 47 | Parameter Sets: (All) 48 | Aliases: 49 | 50 | Required: False 51 | Position: 1 52 | Default value: None 53 | Accept pipeline input: False 54 | Accept wildcard characters: False 55 | ``` 56 | 57 | ### -WhatIf 58 | Shows what would happen if the cmdlet runs. 59 | The cmdlet is not run. 60 | 61 | ```yaml 62 | Type: SwitchParameter 63 | Parameter Sets: (All) 64 | Aliases: wi 65 | 66 | Required: False 67 | Position: Named 68 | Default value: None 69 | Accept pipeline input: False 70 | Accept wildcard characters: False 71 | ``` 72 | 73 | ### -Confirm 74 | Prompts you for confirmation before running the cmdlet. 75 | 76 | ```yaml 77 | Type: SwitchParameter 78 | Parameter Sets: (All) 79 | Aliases: cf 80 | 81 | Required: False 82 | Position: Named 83 | Default value: None 84 | Accept pipeline input: False 85 | Accept wildcard characters: False 86 | ``` 87 | 88 | ### CommonParameters 89 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 90 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 91 | 92 | ## INPUTS 93 | 94 | ## OUTPUTS 95 | 96 | ## NOTES 97 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 98 | DATE 28/06/2017 99 | 100 | ## RELATED LINKS 101 | -------------------------------------------------------------------------------- /docs/functions/Get-SQLDiagSupportedRegions.md: -------------------------------------------------------------------------------- 1 | # Get-SQLDiagSupportedRegions 2 | 3 | ## SYNOPSIS 4 | Returns the list of regions supported for the file upload URI from the SQL Server Diagnostic Analysis API 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Get-SQLDiagSupportedRegions [[-ApiKey] ] [-WhatIf] [-Confirm] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | This function connects to the SQL Server Diagnostic Analysis API and returns a list of supported regions 14 | for the file upload URI 15 | Details here https://ecsapi.portal.azure-api.net/ 16 | 17 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 18 | in a file named SQLDiag.Cred 19 | 20 | ## EXAMPLES 21 | 22 | ### EXAMPLE 1 23 | ``` 24 | Get-SQLDiagSupportedRegions 25 | ``` 26 | 27 | returns a list of supported regions for the file upload URI using an API Key stored in 28 | the users profile in a file named SQLDiag.Cred 29 | 30 | ### EXAMPLE 2 31 | ``` 32 | $APIKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' 33 | ``` 34 | 35 | Get-SQLDiagSupportedRegions -ApiKey $APIKey 36 | 37 | returns a list of supported regions for the file upload URI with the APIKey in the script 38 | 39 | ## PARAMETERS 40 | 41 | ### -ApiKey 42 | The APIKey used to authenticate against the API. 43 | You can get one from https://ecsapi.portal.azure-api.net/ 44 | 45 | ```yaml 46 | Type: String 47 | Parameter Sets: (All) 48 | Aliases: 49 | 50 | Required: False 51 | Position: 1 52 | Default value: None 53 | Accept pipeline input: False 54 | Accept wildcard characters: False 55 | ``` 56 | 57 | ### -WhatIf 58 | Shows what would happen if the cmdlet runs. 59 | The cmdlet is not run. 60 | 61 | ```yaml 62 | Type: SwitchParameter 63 | Parameter Sets: (All) 64 | Aliases: wi 65 | 66 | Required: False 67 | Position: Named 68 | Default value: None 69 | Accept pipeline input: False 70 | Accept wildcard characters: False 71 | ``` 72 | 73 | ### -Confirm 74 | Prompts you for confirmation before running the cmdlet. 75 | 76 | ```yaml 77 | Type: SwitchParameter 78 | Parameter Sets: (All) 79 | Aliases: cf 80 | 81 | Required: False 82 | Position: Named 83 | Default value: None 84 | Accept pipeline input: False 85 | Accept wildcard characters: False 86 | ``` 87 | 88 | ### CommonParameters 89 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 90 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 91 | 92 | ## INPUTS 93 | 94 | ## OUTPUTS 95 | 96 | ## NOTES 97 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 98 | DATE 26/07/2017 99 | 100 | ## RELATED LINKS 101 | -------------------------------------------------------------------------------- /docs/functions/Invoke-SQLDiagDumpAnalysis.md: -------------------------------------------------------------------------------- 1 | # Invoke-SQLDiagDumpAnalysis 2 | 3 | ## SYNOPSIS 4 | Uploads a dump file to the SQL Server Diagnostics API for Analysis 5 | 6 | ## SYNTAX 7 | 8 | ``` 9 | Invoke-SQLDiagDumpAnalysis [-File] [[-ApiKey] ] [-Region] [[-Email] ] 10 | [-WhatIf] [-Confirm] [] 11 | ``` 12 | 13 | ## DESCRIPTION 14 | Uploads a dump file to the SQL Server Diagnostics API for Analysis 15 | Details here https://ecsapi.portal.azure-api.net/ 16 | 17 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 18 | in a file named SQLDiag.Cred 19 | 20 | ## EXAMPLES 21 | 22 | ### EXAMPLE 1 23 | ``` 24 | Invoke-SQLDiagDumpAnalysis -File c:\temp\SQLDump073.mdmp -Region 'West Us' -Email 'a@a.com' 25 | ``` 26 | 27 | Uploads the file to the API and emails when it has completed 28 | 29 | ### EXAMPLE 2 30 | ``` 31 | Get-SQLDiagDumpFile | Invoke-SQLDiagDumpAnalysis -Region 'West US' -Email a@a.com 32 | ``` 33 | 34 | opens a file picker to choose a file which is then uploaded to the West US Azure region 35 | and analysed with the SQL Server Diagnostic API 36 | 37 | ## PARAMETERS 38 | 39 | ### -File 40 | The File Path or File object of the dump file to be analysed 41 | 42 | ```yaml 43 | Type: Object 44 | Parameter Sets: (All) 45 | Aliases: 46 | 47 | Required: True 48 | Position: 1 49 | Default value: None 50 | Accept pipeline input: True (ByPropertyName, ByValue) 51 | Accept wildcard characters: False 52 | ``` 53 | 54 | ### -ApiKey 55 | The APIKey used to authenticate against the API. 56 | You can get one from https://ecsapi.portal.azure-api.net/ 57 | 58 | ```yaml 59 | Type: String 60 | Parameter Sets: (All) 61 | Aliases: 62 | 63 | Required: False 64 | Position: 2 65 | Default value: None 66 | Accept pipeline input: False 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ### -Region 71 | The Azure Region to upload the file to. 72 | Get-SQLDiagSupportedRegions shows the available regions 73 | 74 | ```yaml 75 | Type: String 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: True 80 | Position: 3 81 | Default value: None 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ### -Email 87 | The email address to receive notification that analysis has completed and the recommendations 88 | 89 | ```yaml 90 | Type: Object 91 | Parameter Sets: (All) 92 | Aliases: 93 | 94 | Required: False 95 | Position: 4 96 | Default value: None 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -WhatIf 102 | Shows what would happen if the cmdlet runs. 103 | The cmdlet is not run. 104 | 105 | ```yaml 106 | Type: SwitchParameter 107 | Parameter Sets: (All) 108 | Aliases: wi 109 | 110 | Required: False 111 | Position: Named 112 | Default value: None 113 | Accept pipeline input: False 114 | Accept wildcard characters: False 115 | ``` 116 | 117 | ### -Confirm 118 | Prompts you for confirmation before running the cmdlet. 119 | 120 | ```yaml 121 | Type: SwitchParameter 122 | Parameter Sets: (All) 123 | Aliases: cf 124 | 125 | Required: False 126 | Position: Named 127 | Default value: None 128 | Accept pipeline input: False 129 | Accept wildcard characters: False 130 | ``` 131 | 132 | ### CommonParameters 133 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 134 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 135 | 136 | ## INPUTS 137 | 138 | ## OUTPUTS 139 | 140 | ## NOTES 141 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 142 | DATE 10/07/2017 143 | 144 | ## RELATED LINKS 145 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # SQLDiagAPI 2 | -------------------------------------------------------------------------------- /functions/Get-SQLDiagAnalysis.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns the detail of an analysis from the SQL Server Diagnostics API 4 | 5 | .DESCRIPTION 6 | Connects to the SQL Server Diagnostics API and returns the details of a 7 | single analysis 8 | 9 | .PARAMETER RequestID 10 | The request ID for analysis - You can get this from Get-SQLDiagHistory 11 | 12 | .PARAMETER APIKey 13 | The APIKey used to authenticate against the API. You can get one from https://ecsapi.portal.azure-api.net/ 14 | 15 | .EXAMPLE 16 | Get-SQLDiagAnalysis -RequestID 4b36a572-3925-4f7f-8f5a-bf964582b986 17 | 18 | Returns the Diagnosis analysis for the request id specified 19 | 20 | .EXAMPLE 21 | Get-SQLDiagAnalysisHistory -Since Yesterday | Out-GridView -PassThru | Get-SQLDiagAnalysis 22 | 23 | Gets the Diagnosis history, displays it in Out-GridView and then gets the analysis for the 24 | chosen request 25 | 26 | .NOTES 27 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 28 | DATE 11/07/2017 29 | #> 30 | function Get-SQLDiagAnalysis { 31 | [cmdletbinding(SupportsShouldProcess = $true)] 32 | param( 33 | [parameter(Mandatory = $false)] 34 | [string]$APIKey, 35 | [parameter(Position = 0, 36 | ValueFromPipelineByPropertyName = $true, 37 | ValueFromPipeline = $true, 38 | Mandatory = $true)] 39 | [string]$RequestID) 40 | Begin { 41 | if (!$ApiKey) { 42 | Write-Verbose -Message "Getting the APIKEY" 43 | if (!(Test-Path "${env:\userprofile}\SQLDiag.Cred")) { 44 | Write-Warning "You have not created an XML File to hold the API Key or provided the API Key as a parameter 45 | You can export the key to an XML file using Get-Credential | Export-CliXml -Path `"`${env:\userprofile}\SQLDiag.Cred`" 46 | You can get a key by following the steps here https://ecsapi.portal.azure-api.net/ " 47 | break 48 | } 49 | else { 50 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "Get the APIKey from ${env:\userprofile}\SQLDiag.Cred ")) { 51 | $APIKey = (Import-Clixml -Path "${env:\userprofile}\SQLDiag.Cred").GetNetworkCredential().Password 52 | } 53 | Write-Verbose -Message "Using the APIKEY $APIKey" 54 | } 55 | } 56 | Write-Verbose -Message "Getting the Machine GUID" 57 | $MachineGUID = Get-MachineGUID 58 | 59 | if ($MachineGUID.length -eq 0) { 60 | Write-Warning "Failed to get Machine GUID from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\" 61 | break 62 | } 63 | $headers = @{ "Ocp-Apim-Subscription-Key" = $apiKey } 64 | $AnalysisURL = 'https://ecsapi.azure-api.net/DiagnosticAnalysis/SQLAnalysis/GetAnalysisDetails' 65 | } 66 | Process { 67 | $Body = 68 | @{ 69 | clientId = $MachineGUID 70 | RequestID = $RequestID 71 | } | ConvertTo-Json 72 | try { 73 | Write-Verbose -Message "Getting the Analysis from the API for RequestID $RequestID" 74 | if ($PSCmdlet.ShouldProcess('Analysis Detail APi', "Getting the Analysis History from the API")) { 75 | $invokeRestMethodSplat = @{ 76 | ContentType = "application/json" 77 | ErrorAction = 'Stop' 78 | Headers = $headers 79 | Method = 'Post' 80 | Body = $Body 81 | Uri = $AnalysisURL 82 | } 83 | $Response = Invoke-RestMethod @invokeRestMethodSplat 84 | } 85 | } 86 | catch { 87 | Write-Warning "Failed to get the Analysis History from the API" 88 | Write-Warning -Message "Analysis History URL = $AnalysisUrl" 89 | Write-Warning -Message "Headers = $headers" 90 | Write-Warning -Message "Body = $Body" 91 | break 92 | } 93 | } 94 | End { 95 | Write-Verbose -Message "Returning the Analysis Detail from the API for $RequestId" 96 | $Response 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagAnalysisHistory.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns the SQL Server dump file diagnosis history for this machine from the 4 | SQL Server Diagnostics API 5 | 6 | .DESCRIPTION 7 | Returns the SQL Server dump file diagnosis history for this machine from the 8 | SQL Server Diagnostics API 9 | Details here https://ecsapi.portal.azure-api.net/ 10 | 11 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 12 | in a file named SQLDiag.Cred 13 | 14 | .PARAMETER Status 15 | Status of the request - accepted values are Complete, Failed, In Progress 16 | 17 | .PARAMETER Complete 18 | Filter by Has the analysis completed requires $true or $false 19 | 20 | .PARAMETER Since 21 | Time paramater to filter the history - accepted values 'Today', 'Yesterday', 'This Week', 'This Month' 22 | 23 | .PARAMETER APIKey 24 | The APIKey used to authenticate against the API. You can get one from https://ecsapi.portal.azure-api.net/ 25 | 26 | .EXAMPLE 27 | Get-SQLDiagAnalysisHistory 28 | 29 | Returns the SQL Server dump file diagnosis history for this machine from the 30 | SQL Server Diagnostics API 31 | 32 | .EXAMPLE 33 | Get-SQLDiagAnalysisHistory -Status Complete 34 | 35 | Returns the SQL Server dump file diagnosis history for completed dump Analysis for this machine from the 36 | SQL Server Diagnostics API 37 | 38 | .EXAMPLE 39 | Get-SQLDiagAnalysisHistory -Status Failed 40 | 41 | Returns the SQL Server dump file diagnosis history for dump Analysis that have failed for this machine from the 42 | SQL Server Diagnostics API 43 | 44 | .EXAMPLE 45 | Get-SQLDiagAnalysisHistory -Status 'In Progress' 46 | 47 | Returns the SQL Server dump file diagnosis history for dump Analysis that are in progress for this machine from the 48 | SQL Server Diagnostics API 49 | 50 | .EXAMPLE 51 | Get-SQLDiagAnalysisHistory -Since Today 52 | 53 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight today for this machine from the 54 | SQL Server Diagnostics API 55 | 56 | .EXAMPLE 57 | Get-SQLDiagAnalysisHistory -Since Yesterday 58 | 59 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight Yesterday for this machine from the 60 | SQL Server Diagnostics API 61 | 62 | .EXAMPLE 63 | Get-SQLDiagAnalysisHistory -Since 'This Week' 64 | 65 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight on Monday morning of this week for 66 | this machine from the SQL Server Diagnostics API 67 | 68 | .EXAMPLE 69 | Get-SQLDiagAnalysisHistory -Since 'This Month' 70 | 71 | Returns the SQL Server dump file diagnosis history for dump Analysis since midnight on the 1st of this month for 72 | this machine from the SQL Server Diagnostics API 73 | 74 | .NOTES 75 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 76 | DATE 28/06/2017 77 | #> 78 | function Get-SQLDiagAnalysisHistory { 79 | [cmdletbinding(SupportsShouldProcess = $true)] 80 | param( 81 | [parameter(Mandatory = $false)] 82 | [ValidateSet('In Progress', 'Failed', 'Complete')] 83 | [string]$Status, 84 | [parameter(Mandatory = $false)] 85 | [ValidateSet('Today', 'Yesterday', 'This Week', 'This Month')] 86 | $Since, 87 | [parameter(Mandatory = $false)] 88 | $APIKey 89 | ) 90 | Begin { 91 | if (!$ApiKey) { 92 | Write-Verbose -Message "Getting the APIKEY" 93 | if (!(Test-Path "${env:\userprofile}\SQLDiag.Cred")) { 94 | Write-Warning "You have not created an XML File to hold the API Key or provided the API Key as a parameter 95 | You can export the key to an XML file using Get-Credential | Export-CliXml -Path `"`${env:\userprofile}\SQLDiag.Cred`" 96 | You can get a key by following the steps here https://ecsapi.portal.azure-api.net/ " 97 | break 98 | } 99 | else { 100 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "Get the APIKey from ${env:\userprofile}\SQLDiag.Cred ")) { 101 | $APIKey = (Import-Clixml -Path "${env:\userprofile}\SQLDiag.Cred").GetNetworkCredential().Password 102 | } 103 | Write-Verbose -Message "Using the APIKEY $APIKey" 104 | } 105 | } 106 | Write-Verbose -Message "Getting the Machine GUID" 107 | $MachineGUID = Get-MachineGUID 108 | 109 | if ($MachineGUID.length -eq 0) { 110 | Write-Warning "Failed to get Machine GUID from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\" 111 | break 112 | } 113 | $AnalysisHistoryUrl = 'https://ecsapi.azure-api.net/DiagnosticAnalysis/SQLAnalysis/GetAnalysisHistory/' + $MachineGUID 114 | $headers = @{ "Ocp-Apim-Subscription-Key" = $apiKey } 115 | <# 116 | Swtich $Swtich { 117 | put a swithc here for the inputs to be abel to combine them 118 | }#> 119 | } 120 | Process { 121 | 122 | try { 123 | Write-Verbose -Message "Getting the Analysis History from the API" 124 | if ($PSCmdlet.ShouldProcess('Analysis History APi', "Getting the Analysis History from the API")) { 125 | $invokeRestMethodSplat = @{ 126 | ContentType = "application/json" 127 | Headers = $headers 128 | Method = 'Get' 129 | Uri = $AnalysisHistoryUrl 130 | ErrorAction = 'Stop' 131 | } 132 | $response = Invoke-RestMethod @invokeRestMethodSplat 133 | } 134 | } 135 | catch { 136 | Write-Warning "Failed to get the Analysis History from the API" 137 | Write-Warning -Message "Analysis History URL = $AnalysisHistoryUrl" 138 | Write-Warning -Message "Headers = $headers" 139 | Write-Warning -Message "Body = $Body" 140 | break 141 | } 142 | if ($status) { 143 | Write-Verbose -Message "Filtering By Status $Status" 144 | $response | Where-Object {$_.RequestStatus -eq $status} 145 | } 146 | elseif ($Since) { 147 | if ($Since -eq 'Today') { 148 | $Date = [datetime]::Today 149 | } 150 | elseif ($Since -eq 'Yesterday') { 151 | $Date = ([datetime]::Today).AddDays(-1) 152 | } 153 | elseif ($Since -eq 'This Week') { 154 | $n = 0 155 | do { 156 | $date = (Get-Date -Hour 0 -Minute 0 -Second 0).AddDays( - $n) 157 | $n++ 158 | } 159 | Until ( $date.DayOfWeek -eq "Monday" ) 160 | } 161 | elseif ($Since -eq 'This Month') { 162 | $Today = [datetime]::Today 163 | $getDateSplat = @{ 164 | Year = $today.Year 165 | Hour = 0 166 | Month = $today.Month 167 | Second = 0 168 | Day = 1 169 | Minute = 0 170 | } 171 | $Date = Get-Date @getDateSplat 172 | } 173 | Write-Verbose -Message "Filtering By Date since $Date" 174 | $response | Where-Object {[datetime]$_.CreateTime -gt $Date} 175 | } 176 | else { 177 | Write-Verbose -Message "Returning default response" 178 | $response 179 | } 180 | } 181 | End { 182 | 183 | } 184 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagDumpFile.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Gets a SQL Server Dump File for uploading to the API 4 | 5 | .DESCRIPTION 6 | Gets a SQL Server Dump File for uploading to the API. 7 | Opens a graphical file picker if no file specified 8 | 9 | .PARAMETER file 10 | Path to file 11 | 12 | .EXAMPLE 13 | Get-SQLDiagDumpFile | Invoke-SQLDiagDumpAnalysis -Region 'West US' -Email a@a.com 14 | 15 | opens a file picker to choose a file which is then uploaded to teh West US Azure region 16 | and analysed with the SQL Server Diagnostic API 17 | 18 | .NOTES 19 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 20 | DATE 07/07/2017 21 | #> 22 | function Get-SQLDiagDumpFile { 23 | [cmdletbinding(SupportsShouldProcess)] 24 | param( 25 | [parameter(ValueFromPipelineByPropertyName, 26 | Mandatory = $false)] 27 | [ValidateScript( {Test-Path -Path $_})] 28 | [string]$file 29 | ) 30 | Begin { 31 | } 32 | Process { 33 | if (!$file) { 34 | try { 35 | Write-Verbose -Message "No file specified so invoking File Picker" 36 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "invoking File Picker")) { 37 | $DumpFile = Invoke-FilePicker 38 | } 39 | } 40 | catch { 41 | Write-Warning -Message "Failed to Get File information" 42 | } 43 | } 44 | else { 45 | try { 46 | Write-Verbose -Message "Getting information about $File" 47 | if ($PSCmdlet.ShouldProcess($File, "Getting file information")) { 48 | $DumpFile = Get-Item $File 49 | } 50 | } 51 | catch { 52 | Write-Warning -Message "Failed to Get File information about $File" 53 | } 54 | } 55 | } 56 | End { 57 | Write-Verbose -Message "Returning file object" 58 | [pscustomobject]@{ 59 | FullName = $DumpFile.FullName 60 | Length = $DumpFile.Length 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagFeature.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns the Features avaialble from teh SQL Server Diagnostic Recommendations API 4 | 5 | .DESCRIPTION 6 | This will connect to to the SQL Server Diagnostic Recommendations API and return the 7 | unique list of features for some or all of the Products 8 | 9 | .PARAMETER Recommendations 10 | The recommendation object from the API - Use Get-SQLDiagRecommendations by default 11 | 12 | .PARAMETER Product 13 | The product or products that you want to filter by Get-SQLDiagProduct will show the options 14 | 15 | .PARAMETER Feature 16 | Wildcard case insensitive search for feature name 17 | 18 | .EXAMPLE 19 | Get-SQLDiagFeature 20 | 21 | This will return a unique list of all of the Feature Areas that have fixes from the SQL Server Diagnostic API 22 | 23 | .EXAMPLE 24 | Get-SQLDiagFeature -Feature Always 25 | 26 | This will return a unique list of all of the Feature Areas that have fixes from the SQL Server Diagnostic API 27 | with a name including Always (case insensitive) 28 | 29 | .EXAMPLE 30 | Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' 31 | 32 | This will return a unique list of all of the Feature Areas that have fixes for the product SQL Server 2012 SP3 33 | from the SQL Server Diagnostic API 34 | 35 | .EXAMPLE 36 | Get-SQLDiagProduct 2016 | Get-SQLDiagFeature 37 | 38 | This will return a unique list of all of the Feature Areas that have fixes for products with 2016 in the name 39 | from the SQL Server Diagnostic API 40 | 41 | .EXAMPLE 42 | Get-SQLDiagProduct 2016 | Get-SQLDiagFeature Always 43 | 44 | This will return a unique list of all of the Feature Areas that have fixes for products with 2016 in the name 45 | and features with Always in the name (case insensitive) from the SQL Server Diagnostic API 46 | 47 | .NOTES 48 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 49 | DATE 30/06/2017 50 | #> 51 | function Get-SQLDiagFeature { 52 | [cmdletbinding()] 53 | Param( 54 | [parameter(ValueFromPipelineByPropertyName, 55 | Mandatory = $false)] 56 | [ValidateNotNull()] 57 | [pscustomobject] $Recommendations = (Get-SQLDiagRecommendations), 58 | [parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 59 | [ValidateScript( {Get-SQLDiagProduct})] 60 | [object[]]$Product, 61 | [parameter(Mandatory = $false, Position = 0)] 62 | [String[]]$Feature 63 | ) 64 | Begin { 65 | # Define empty features array 66 | $features = @() 67 | } 68 | Process { 69 | 70 | # If no product grab all of the features and add them to the features array if not already there 71 | if (!($Product)) { 72 | Write-Verbose -Message "Getting all of the features" 73 | foreach ($recommendation in $recommendations.Recommendations) { 74 | foreach ($fix in $recommendation.Content.RelevantFixes) { 75 | $feat = $fix.Title 76 | if ($features -notcontains $feat) { 77 | $Features += $Feat 78 | } 79 | } 80 | } 81 | Write-Verbose -Message "Got all of the features" 82 | } 83 | else { 84 | Write-Verbose -Message "Getting all of the features for $Product" 85 | # If product grab all of the features for that product and add them to the features array if not already there 86 | foreach ($P in $Product) { 87 | foreach ($recommendation in $recommendations.Recommendations) { 88 | $Products = $recommendation.Product 89 | if ($products -notcontains $p) {continue} 90 | foreach ($fix in $recommendation.Content.RelevantFixes) { 91 | $feat = $fix.Title 92 | if ($features -notcontains $feat) { 93 | $Features += $Feat 94 | } 95 | } 96 | } 97 | } 98 | Write-Verbose -Message "Got all of the features for $product" 99 | } 100 | 101 | } 102 | End { 103 | ## if feature search return only features that match the search term alphabetically 104 | if ($Feature) { 105 | Write-Verbose -Message "Sorting the Features for $feature" 106 | $features | Where-Object {$_ -like "*$($Feature)*"} | Sort-Object 107 | Write-Verbose -Message "Returnign the Features for $feature" 108 | } 109 | ## otherwise return the lot alphabetically 110 | else { 111 | Write-Verbose -Message "Sorting the Features" 112 | $features | Sort-Object 113 | Write-Verbose -Message "Returning the Features" 114 | } 115 | } 116 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagFix.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns the Fixes from the SQL Server Diagnostic recommnendations API 4 | 5 | .DESCRIPTION 6 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for the 7 | Fixes in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 8 | 9 | .PARAMETER Recommendations 10 | The recommendation object from the API - Uses Get-SQLDiagRecommendations by default 11 | 12 | .PARAMETER Product 13 | The product or products that you want to filter by Get-SQLDiagProduct will show the options 14 | 15 | .PARAMETER Feature 16 | The Feature Name or Area that you want to filter by Get-SQLDiagFeature will show the options 17 | 18 | .EXAMPLE 19 | Get-SQLDiagFix 20 | 21 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the 22 | Fixes in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 23 | 24 | .EXAMPLE 25 | Get-SQLDiagFix -Product 'SQL Server 2012 SP3' 26 | 27 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for 28 | SQL Server 2012 SP3 in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 29 | 30 | .EXAMPLE 31 | Get-SQLDiagFix -Feature 'Always On' 32 | 33 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 34 | Feature Area Always On in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 35 | 36 | .EXAMPLE 37 | Get-SQLDiagFix 'Always On' 38 | 39 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 40 | Feature Area Always On in the Cumulative Updates returned from the SQL Server Diagnostics Recommendations API 41 | 42 | .EXAMPLE 43 | Get-SQLDiagFix -Product 'SQL Server 2012 SP3' -Feature 'Always On' 44 | 45 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 46 | Feature Area Always On for SQL Server 2012 SP3 in the Cumulative Updates returned from the SQL Server 47 | Diagnostics Recommendations API 48 | 49 | .EXAMPLE 50 | Get-SQLDiagProduct 2012 | Get-SQLDiagFix 51 | 52 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 53 | Feature Area Always On for products with 2012 in the name in the Cumulative Updates returned from 54 | the SQL Server Diagnostics Recommendations API 55 | 56 | .EXAMPLE 57 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix 58 | 59 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 60 | Feature Area Always On for products with SP1 in the name in the Cumulative Updates returned from 61 | the SQL Server Diagnostics Recommendations API 62 | 63 | .EXAMPLE 64 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix -Feature (Get-SQLDiagFeature -Feature AL) 65 | 66 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 67 | Feature Areas with AL in the name for products with SP1 in the name in the Cumulative Updates returned 68 | from the SQL Server Diagnostics Recommendations API 69 | 70 | .EXAMPLE 71 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix -Feature (Get-SQLDiagFeature -Feature AL) | Out-GridView 72 | 73 | Returns the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes for the 74 | Feature Areas with AL in the name for products with SP1 in the name in the Cumulative Updates returned 75 | from the SQL Server Diagnostics Recommendations API and displays them in Out-GridView 76 | 77 | .EXAMPLE 78 | Get-SQLDiagFix | Export-Csv -Path C:\temp\Fixes.csv 79 | 80 | Exports the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes in the 81 | Cumulative Updates returned from the SQL Server Diagnostics Recommendations API into a File 82 | 83 | .EXAMPLE 84 | $Fixes = Get-SQLDiagFix | Out-DbaDataTable 85 | Write-DbaDataTable -SqlServer $Server -Database $DB -InputObject $Fixes-Table Fixes -AutoCreateTable 86 | 87 | Puts the Product Name, Feature Name/Area, KB Number, Title and URL for all of the Fixes in the 88 | Cumulative Updates returned from the SQL Server Diagnostics Recommendations API into a 89 | database table and creates the table - Requires dbatools https://dbatools.io 90 | 91 | .EXAMPLE 92 | Get-SQLDiagProduct SP1 | Get-SQLDiagFix -Feature (Get-SQLDiagFeature -Feature AL) | Out-GridView -PassThru | ForEach-Object {Start-Process $_.UR} 93 | 94 | Opens the URL for a Fix that the user chooses from Out-GridView which is populated with all of the Fixes for the 95 | Feature Areas with AL in the name for products with SP1 in the name in the Cumulative Updates returned 96 | from the SQL Server Diagnostics Recommendations API 97 | 98 | .NOTES 99 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 100 | DATE 03/07/2017 101 | #> 102 | function Get-SQLDiagFix { 103 | [cmdletbinding()] 104 | Param( 105 | [parameter(ValueFromPipelineByPropertyName, 106 | Mandatory = $false)] 107 | [ValidateNotNull()] 108 | [pscustomobject] $Recommendations = (Get-SQLDiagRecommendations), 109 | [parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 110 | [ValidateScript( {Get-SQLDiagProduct})] 111 | [object[]]$Product, 112 | [parameter(Mandatory = $false, Position = 0)] 113 | [String[]]$Feature 114 | ) 115 | Begin {} 116 | Process { 117 | if ($Product -and $feature) { 118 | Write-Verbose -Message "Getting the fixes for $product and $feature" 119 | foreach ($P in $Product) { 120 | foreach ($recommendation in $recommendations.Recommendations | Where-Object {$_.Product -eq $P}) { 121 | $ProductName = $recommendation.Product 122 | foreach ($f in $feature) { 123 | foreach ($fix in $recommendation.Content.RelevantFixes | Where-Object {$_.Title -eq $F}) { 124 | $feat = $fix.Title 125 | foreach ($kb in $fix.KbArticles) { 126 | [PSCustomObject]@{ 127 | Product = $ProductName 128 | Feature = $feat 129 | KB = $kb.Rel 130 | Title = $Kb.title 131 | URL = $kb.Href 132 | } 133 | } 134 | } 135 | } 136 | } 137 | } 138 | Write-Verbose -Message "Got the fixes for $product and $feature" 139 | } 140 | elseif ($Product) { 141 | Write-Verbose -Message "Getting the fixes for $product" 142 | foreach ($P in $Product) { 143 | foreach ($recommendation in $recommendations.Recommendations | Where-Object {$_.Product -eq $P}) { 144 | $ProductName = $recommendation.Product 145 | foreach ($fix in $recommendation.Content.RelevantFixes) { 146 | $feat = $fix.Title 147 | foreach ($kb in $fix.KbArticles) { 148 | [PSCustomObject]@{ 149 | Product = $ProductName 150 | Feature = $feat 151 | KB = $kb.Rel 152 | Title = $Kb.title 153 | URL = $kb.Href 154 | } 155 | } 156 | } 157 | } 158 | Write-Verbose -Message "Got the fixes for $product" 159 | } 160 | } 161 | elseif ($feature) { 162 | Write-Verbose -Message "Getting the fixes for $feature" 163 | foreach ($recommendation in $recommendations.Recommendations) { 164 | $ProductName = $recommendation.Product 165 | foreach ($f in $feature) { 166 | foreach ($fix in $recommendation.Content.RelevantFixes | Where-Object {$_.Title -eq $F}) { 167 | $feat = $fix.Title 168 | foreach ($kb in $fix.KbArticles) { 169 | [PSCustomObject]@{ 170 | Product = $ProductName 171 | Feature = $feat 172 | KB = $kb.Rel 173 | Title = $Kb.title 174 | URL = $kb.Href 175 | } 176 | } 177 | } 178 | } 179 | } 180 | Write-Verbose -Message "Got the fixes for $feature" 181 | } 182 | else { 183 | Write-Verbose -Message "Getting all of the fixes" 184 | foreach ($recommendation in $recommendations.Recommendations) { 185 | $ProductName = $recommendation.Product 186 | foreach ($fix in $recommendation.Content.RelevantFixes) { 187 | $feat = $fix.Title 188 | foreach ($kb in $fix.KbArticles) { 189 | [PSCustomObject]@{ 190 | Product = $ProductName 191 | Feature = $feat 192 | KB = $kb.Rel 193 | Title = $Kb.title 194 | URL = $kb.Href 195 | } 196 | } 197 | } 198 | } 199 | Write-Verbose -Message "Got all of the fixes" 200 | } 201 | } 202 | 203 | End {} 204 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagLatestAnalysis.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns information about the latest diagnosis from the SQL Server Diagnostic API 4 | 5 | .DESCRIPTION 6 | Returns information about the latest diagnosis from the SQL Server Diagnostic API 7 | 8 | .EXAMPLE 9 | Get-SQLDiagLatestAnalysis 10 | 11 | Returns information about the latest diagnosis from the SQL Server Diagnostic API 12 | 13 | .NOTES 14 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 15 | DATE 11/07/2017 16 | 17 | #> 18 | function Get-SQLDiagLatestAnalysis { 19 | Write-Verbose -Message "Getting all of the Diagnosis history" 20 | try { 21 | $history = Get-SQLDiagAnalysisHistory 22 | Write-Verbose -Message "got all of the diagnosis history" 23 | } 24 | catch { 25 | Write-Warning "Failed to get all of the diagnosis history" 26 | break 27 | } 28 | Write-Verbose -Message "Filtering history by latest" 29 | $RequestID = ($History | Sort-Object CreateTime -Descending | Select-Object -First 1).RequestID 30 | Write-Verbose -Message "Getting the latest Diagnosis" 31 | Get-SQLDiagAnalysis -RequestID $RequestID 32 | Write-Verbose -Message "Got the latest Diagnosis" 33 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagLatestCU.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Gets The Latest Cumulative Updates and Date from the SQL Server Diagnostic API 4 | 5 | .DESCRIPTION 6 | Returns Product Name, Cumulative Update Name and Date created from the SQL Server Diagnostic API 7 | Opens the Learn More webpage with the LearnMore switch 8 | Downloads the CU with the Download Switch 9 | 10 | .PARAMETER Recommendations 11 | The recommendation object from the API - Use Get-SQLDiagRecommendations by default 12 | 13 | .PARAMETER Product 14 | The product or products that you want to filter by Get-SQLDiagProduct will show the options 15 | 16 | .PARAMETER LearnMore 17 | Opens the Information web-page for the Cumulative Update for the product specified in the default browser 18 | 19 | .PARAMETER Download 20 | Opens the Download page for the Cumulative Update for the product specified in the default browser 21 | 22 | .EXAMPLE 23 | Get-SQLDiagLatestCU 24 | 25 | Returns Product Name, Cumulative Update Name and Date created for all products from the SQL Server Diagnostic API 26 | 27 | .EXAMPLE 28 | Get-SQLDiagRecommendations | Get-SQLDiagLatestCU 29 | 30 | Returns Product Name, Cumulative Update Name and Date created for all products from the SQL Server Diagnostic API 31 | 32 | .EXAMPLE 33 | Get-SQLDiagLatestCU -Recommendations (Get-SQLDiagRecommendations) 34 | 35 | Returns Product Name, Cumulative Update Name and Date created for all products from the SQL Server Diagnostic API 36 | 37 | .EXAMPLE 38 | Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU 39 | 40 | Returns Product Name, Cumulative Update Name and Date created for products named 2012 from the SQL Server Diagnostic API 41 | 42 | .EXAMPLE 43 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' 44 | 45 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 from the SQL Server Diagnostic API 46 | 47 | .EXAMPLE 48 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3','SQL Server 2014 SP1' 49 | 50 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 and SQL Server 2014 SP1 from the 51 | SQL Server Diagnostic API 52 | 53 | .EXAMPLE 54 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' -LearnMore 55 | 56 | Opens the Cumulative Update for SQL Server 2012 SP3 information webpage in the default browser 57 | 58 | .EXAMPLE 59 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' -Download 60 | 61 | Opens the Cumulative Update for SQL Server 2012 SP3 download webpage in the default browser 62 | 63 | .EXAMPLE 64 | Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU -LearnMore 65 | 66 | Opens the Cumulative Update for SQL Server 2012 SP3 information webpage in the default browser 67 | 68 | .EXAMPLE 69 | Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU -Download 70 | 71 | Opens the Cumulative Update for SQL Server 2012 SP3 download webpage in the default browser 72 | 73 | .EXAMPLE 74 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3','SQL Server 2014 SP1' | Out-GridView 75 | 76 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 and SQL Server 2014 SP1 from the 77 | SQL Server Diagnostic API and outputs to Out-GridView 78 | 79 | .EXAMPLE 80 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3','SQL Server 2014 SP1' | Out-File C:\Temp\LatestCU.txt 81 | 82 | Returns Product Name, Cumulative Update Name and Date created for SQL Server 2012 SP3 and SQL Server 2014 SP1 from the 83 | SQL Server Diagnostic API and outputs to a File C:\Temp\LatestCU.txt 84 | 85 | .EXAMPLE 86 | $LatestCu = Get-SQLDiagLatestCU | Out-DbaDataTable 87 | Write-DbaDataTable -SqlServer $Server -Database $DB -InputObject $LatestCu-Table $LatestCu -AutoCreateTable 88 | 89 | Puts Product Name, Cumulative Update Name and Date created for all products from the 90 | SQL Server Diagnostic API into a database table and creates the table - Requires dbatools https://dbatools.io 91 | 92 | .NOTES 93 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 94 | DATE 30/06/2017 95 | #> 96 | function Get-SQLDiagLatestCU { 97 | [cmdletbinding(SupportsShouldProcess)] 98 | Param( 99 | [parameter(ValueFromPipelineByPropertyName, 100 | Mandatory = $false)] 101 | [ValidateNotNull()] 102 | [pscustomobject] $Recommendations = (Get-SQLDiagRecommendations), 103 | [parameter(Mandatory = $false, ValueFromPipeline = $true, Position = 0)] 104 | [ValidateScript( {Get-SQLDiagProduct})] 105 | [String[]]$Product, 106 | [switch]$LearnMore, 107 | [switch]$Download 108 | ) 109 | ## Much as I would love to have Products dynamically populated from the Recommendations parameter, this will not work for the pipeline 110 | ## I can make it work if Recommendations is a parameter but it needs to work for the pipeline too 111 | ## If anyone know how to do this I would be grateful 112 | Begin {} 113 | Process { 114 | 115 | ## We only want one product to open a learnmore web-page 116 | if ($LearnMore -and $Product.Count -ne 1) { 117 | Write-Warning "The Learn More switch requires a single Product so that it only opens one browser window." 118 | break 119 | } 120 | 121 | ## If we have one product and the learnmore switch open the web-page 122 | elseif ($LearnMore -and $Product.Count -eq 1) { 123 | Write-Verbose -Message "Opening default browser for latest CU for the product $Product" 124 | $URL = (($recommendations.Recommendations | Where-Object {$_.Product -eq $product}).Content.ExternalLinks | Where-Object {$_.Rel -eq 'LearnMore'}).Href 125 | try { 126 | if ($PSCmdlet.ShouldProcess($Url, "Opening Default Browser for the Latest CU")) { 127 | Start-Process $Url 128 | Write-Verbose -Message "Opened default browser for latest CU for the product $Product" 129 | break 130 | } 131 | } 132 | catch { 133 | Write-Warning "Failed to open default browser" 134 | } 135 | } 136 | ## We only want one product to download 137 | elseif ($Download -and $Product.Count -ne 1) { 138 | Write-Warning "The Download switch requires a single Product" 139 | break 140 | } 141 | 142 | elseif ($Download -and $Product.Count -eq 1) { 143 | Write-Verbose -Message "Opening default browser for the download page for the product $Product" 144 | $URL = (($recommendations.Recommendations | Where-Object {$_.Product -eq $product}).Content.ExternalLinks | Where-Object {$_.Rel -eq 'Download'}).Href 145 | try { 146 | if ($PSCmdlet.ShouldProcess($Url, "Opening Default Browser for the download page")) { 147 | Start-Process $Url 148 | Write-Verbose -Message "Opened default browser for the download page for the product $Product" 149 | break 150 | } 151 | } 152 | catch { 153 | Write-Warning "Failed to open default browser" 154 | } 155 | } 156 | ## If no Product specified display information for all Products 157 | elseif (!($Product)) { 158 | Write-Verbose -Message "Displaying Latest CU information for All Products" 159 | foreach ($recommendation in $recommendations.Recommendations) { 160 | $ProductName = $recommendation.Product 161 | $CU = $recommendation.Title 162 | $CreatedOn = $recommendation.CreatedOn 163 | [PSCustomObject]@{ 164 | Product = $ProductName 165 | CU = $CU 166 | CreatedOn = $CreatedOn 167 | } 168 | } 169 | Write-Verbose -Message "Displayed Latest CU information for All Products" 170 | } 171 | 172 | ## Otherwise display information for specified product 173 | else { 174 | Write-Verbose -Message "Displaying Latest CU information for Products $Products" 175 | foreach ($recommendation in $recommendations.Recommendations | Where-Object {$_.Product -in $Product}) { 176 | $ProductName = $recommendation.Product 177 | $CU = $recommendation.Title 178 | $CreatedOn = $recommendation.CreatedOn 179 | [PSCustomObject]@{ 180 | Product = $ProductName 181 | CU = $CU 182 | CreatedOn = $CreatedOn 183 | } 184 | } 185 | Write-Verbose -Message "Displayed Latest CU information for Products $Products" 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /functions/Get-SQLDiagProduct.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns the Products avaiable in the SQL Server Diagnostic API 4 | 5 | .DESCRIPTION 6 | Enables you to search for the products that are available in the SQL Server Diagnostic API 7 | 8 | .PARAMETER Recommendations 9 | The recommendation object from the API - Uses Get-SQLDiagRecommendations by default 10 | 11 | .PARAMETER Product 12 | The search for the product you do not need to enter wildcards 13 | 14 | .EXAMPLE 15 | Get-SQLDiagProduct 16 | 17 | Returns all of the Product Names in the SQL Server Diagnostic API 18 | 19 | .EXAMPLE 20 | Get-SQLDiagRecommendations | Get-SQLDiagProduct 21 | 22 | Returns all of the Product Names in the SQL Server Diagnostic API 23 | 24 | .EXAMPLE 25 | Get-SQLDiagProduct -Product 2012 26 | 27 | Returns all of the Product Names in the SQL Server Diagnostic API with 2012 in the name 28 | 29 | .EXAMPLE 30 | Get-SQLDiagProduct -Product SP1 31 | 32 | Returns all of the Product Names in the SQL Server Diagnostic API with SP1 in the name 33 | 34 | .EXAMPLE 35 | Get-SQLDiagProduct SP1 36 | 37 | Returns all of the Product Names in the SQL Server Diagnostic API with SP1 in the name 38 | 39 | .EXAMPLE 40 | $product = Get-SQLDiagProduct -Product 2016 41 | Get-SQLDiagLatestCU -Product $product 42 | 43 | Returns Product Name, Cumulative Update Name and Date created for products with 2016 in the name from the 44 | SQL Server Diagnostic API 45 | 46 | .NOTES 47 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 48 | DATE 30/06/2017 49 | #> 50 | function Get-SQLDiagProduct { 51 | [cmdletbinding()] 52 | Param( 53 | [parameter(ValueFromPipelineByPropertyName, 54 | ValueFromPipeline, 55 | Mandatory = $false)] 56 | [ValidateNotNull()] 57 | [pscustomobject]$Recommendations = (Get-SQLDiagRecommendations), 58 | [parameter(ValueFromPipelineByPropertyName, 59 | ValueFromPipeline, Position = 0, 60 | Mandatory = $false)] 61 | [String]$Product 62 | ) 63 | if(!($Product)){ 64 | Write-Verbose -Message "Getting All the Products from the API" 65 | $recommendations.Recommendations.Product 66 | Write-Verbose -Message "Got the Products from the API" 67 | } 68 | else{ 69 | Write-Verbose -Message "Getting the products from the API filtered by $Product" 70 | $recommendations.Recommendations.Product | Where-Object {$_ -like "*$($Product)*"} 71 | Write-Verbose -Message "Got the Products from the API" 72 | } 73 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagRecommendations.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Uses the SQL Server Diagnostic Recommendations API to return latest CU information as an object 4 | 5 | .DESCRIPTION 6 | This function connects to the SQL Server Diagnostic Recommendations API and returns a PSCustomObject 7 | with information about the latest Cumulative Updates for various SQL Server Versions. 8 | Details here https://ecsapi.portal.azure-api.net/ 9 | 10 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 11 | in a file named SQLDiag.Cred 12 | 13 | .PARAMETER ApiKey 14 | The APIKey used to authenticate against the API. You can get one from https://ecsapi.portal.azure-api.net/ 15 | 16 | .EXAMPLE 17 | Get-SQLDiagRecommendations 18 | 19 | Returns an object containing the information about the latest CUs for SQL Server using an API Key stored in 20 | the users profile in a file named SQLDiag.Cred 21 | 22 | .EXAMPLE 23 | $APIKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' 24 | Get-SQLDiagRecommendations -ApiKey $APIKey 25 | 26 | Returns an object containing the information about the latest CUs for SQL Server 27 | 28 | .NOTES 29 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 30 | DATE 28/06/2017 31 | 32 | #> 33 | function Get-SQLDiagRecommendations { 34 | [cmdletbinding(SupportsShouldProcess)] 35 | Param([string]$ApiKey) 36 | if (!$ApiKey) { 37 | Write-Verbose -Message "Getting the APIKey" 38 | if (!(Test-Path "${env:\userprofile}\SQLDiag.Cred")) { 39 | Write-Warning "You have not created an XML File to hold the API Key or provided the API Key as a parameter 40 | You can export the key to an XML file using Get-Credential | Export-CliXml -Path `"`${env:\userprofile}\SQLDiag.Cred`" 41 | You can get a key by following the steps here https://ecsapi.portal.azure-api.net/ " 42 | break 43 | } 44 | else { 45 | $APIKey = (Import-Clixml -Path "${env:\userprofile}\SQLDiag.Cred").GetNetworkCredential().Password 46 | Write-Verbose -Message "Got the API Key $APIKey" 47 | } 48 | } 49 | Write-Verbose -Message "Getting the Machine GUID" 50 | $MachineGUID = Get-MachineGUID 51 | 52 | if($MachineGUID.length -eq 0) 53 | { 54 | Write-Warning "Failed to get Machine GUID from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\" 55 | break 56 | } 57 | Write-Verbose -Message "Getting the LatestCUs from the API" 58 | $apiUrl = "https://ecsapi.azure-api.net/SQLServer/recommendations/latestcus/" + $MachineGUID + "?api-version=2017-06-01" 59 | $headers = @{ "Ocp-Apim-Subscription-Key" = $apiKey } 60 | try { 61 | if ($PSCmdlet.ShouldProcess($apiUrl, "Connecting to API to get Latest CUs")) { 62 | $invokeRestMethodSplat = @{ 63 | Method = 'Get' 64 | Uri = $apiUrl 65 | ContentType = "application/json" 66 | Headers = $headers 67 | ErrorAction = 'Stop' 68 | } 69 | Invoke-RestMethod @invokeRestMethodSplat 70 | } 71 | } 72 | catch { 73 | Write-Warning "Failed to get Latest CUs from the API $APIURL" 74 | } 75 | Write-Verbose -Message "Got the Latest CUs" 76 | } -------------------------------------------------------------------------------- /functions/Get-SQLDiagSupportedRegions.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns the list of regions supported for the file upload URI from the SQL Server Diagnostic Analysis API 4 | 5 | .DESCRIPTION 6 | This function connects to the SQL Server Diagnostic Analysis API and returns a list of supported regions 7 | for the file upload URI 8 | Details here https://ecsapi.portal.azure-api.net/ 9 | 10 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 11 | in a file named SQLDiag.Cred 12 | 13 | .PARAMETER ApiKey 14 | The APIKey used to authenticate against the API. You can get one from https://ecsapi.portal.azure-api.net/ 15 | 16 | .EXAMPLE 17 | Get-SQLDiagSupportedRegions 18 | 19 | returns a list of supported regions for the file upload URI using an API Key stored in 20 | the users profile in a file named SQLDiag.Cred 21 | 22 | .EXAMPLE 23 | $APIKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' 24 | Get-SQLDiagSupportedRegions -ApiKey $APIKey 25 | 26 | returns a list of supported regions for the file upload URI with the APIKey in the script 27 | 28 | .NOTES 29 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 30 | DATE 26/07/2017 31 | 32 | #> 33 | function Get-SQLDiagSupportedRegions { 34 | [cmdletbinding(SupportsShouldProcess = $true)] 35 | Param([string]$ApiKey) 36 | if (!$ApiKey) { 37 | Write-Verbose -Message "Getting the APIKey" 38 | if (!(Test-Path "${env:\userprofile}\SQLDiag.Cred")) { 39 | Write-Warning "You have not created an XML File to hold the API Key or provided the API Key as a parameter 40 | You can export the key to an XML file using Get-Credential | Export-CliXml -Path `"`${env:\userprofile}\SQLDiag.Cred`" 41 | You can get a key by following the steps here https://ecsapi.portal.azure-api.net/ " 42 | break 43 | } 44 | else { 45 | $APIKey = (Import-Clixml -Path "${env:\userprofile}\SQLDiag.Cred").GetNetworkCredential().Password 46 | Write-Verbose -Message "Got the API Key $APIKey" 47 | } 48 | } 49 | Write-Verbose -Message "Getting the Machine GUID" 50 | $MachineGUID = Get-MachineGUID 51 | 52 | if ($MachineGUID.length -eq 0) { 53 | Write-Warning "Failed to get Machine GUID from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\" 54 | break 55 | } 56 | 57 | Write-Verbose -Message "Getting the Supported Regions from the API" 58 | $apiUrl = "https://ecsapi.azure-api.net/DiagnosticAnalysis/SQLAnalysis/GetSupportedRegions?api-version=2017-06-01" 59 | $headers = @{ "Ocp-Apim-Subscription-Key" = $apiKey } 60 | try { 61 | if ($PSCmdlet.ShouldProcess($apiUrl, "Connecting to API to get Supported Regions")) { 62 | $invokeRestMethodSplat = @{ 63 | Uri = $apiUrl 64 | ContentType = "application/json" 65 | Method = 'Get' 66 | Headers = $headers 67 | ErrorAction = 'Stop' 68 | } 69 | Invoke-RestMethod @invokeRestMethodSplat 70 | } 71 | } 72 | catch { 73 | Write-Warning " Failed to get Supported Regions from the API $APIURL" 74 | } 75 | Write-Verbose -Message "Got the Supported Regions" 76 | } -------------------------------------------------------------------------------- /functions/Invoke-SQLDiagDumpAnalysis.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Uploads a dump file to the SQL Server Diagnostics API for Analysis 4 | 5 | .DESCRIPTION 6 | Uploads a dump file to the SQL Server Diagnostics API for Analysis 7 | Details here https://ecsapi.portal.azure-api.net/ 8 | 9 | It requires the APIKey parameter or the APIKey to be stored using Export-CliXML in the users profile 10 | in a file named SQLDiag.Cred 11 | 12 | .PARAMETER File 13 | The File Path or File object of the dump file to be analysed 14 | 15 | .PARAMETER ApiKey 16 | The APIKey used to authenticate against the API. You can get one from https://ecsapi.portal.azure-api.net/ 17 | 18 | .PARAMETER Region 19 | The Azure Region to upload the file to. Get-SQLDiagSupportedRegions shows the available regions 20 | 21 | .PARAMETER Email 22 | The email address to receive notification that analysis has completed and the recommendations 23 | 24 | .EXAMPLE 25 | Invoke-SQLDiagDumpAnalysis -File c:\temp\SQLDump073.mdmp -Region 'West Us' -Email 'a@a.com' 26 | 27 | Uploads the file to the API and emails when it has completed 28 | 29 | .EXAMPLE 30 | Get-SQLDiagDumpFile | Invoke-SQLDiagDumpAnalysis -Region 'West US' -Email a@a.com 31 | 32 | opens a file picker to choose a file which is then uploaded to the West US Azure region 33 | and analysed with the SQL Server Diagnostic API 34 | 35 | .NOTES 36 | AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 37 | DATE 10/07/2017 38 | #> 39 | function Invoke-SQLDiagDumpAnalysis { 40 | [cmdletbinding(SupportsShouldProcess = $true)] 41 | param( 42 | [parameter(ValueFromPipelineByPropertyName, 43 | ValueFromPipeline, 44 | Mandatory = $true)] 45 | [ValidateNotNull()] 46 | [object]$File, 47 | [parameter( Mandatory = $false)] 48 | [string]$ApiKey, 49 | [parameter( Mandatory = $true)] 50 | [ValidateScript( {Get-SQLDiagSupportedRegions})] 51 | [string]$Region, 52 | [parameter( Mandatory = $false)] 53 | [ValidatePattern('\w+@\w+\.\w+')] 54 | $Email 55 | ) 56 | Begin { 57 | # Get the Machine Guid and the APIKey and the file information 58 | Write-Verbose -Message "Getting the Machine GUID" 59 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "Get the GUID from the registry")) { 60 | $MachineGUID = Get-MachineGUID 61 | } 62 | Write-Verbose -Message "Got the Machine GUID - $MachineGUID" 63 | if (!$ApiKey) { 64 | Write-Verbose -Message "Getting the APIKEY" 65 | if (!(Test-Path "${env:\userprofile}\SQLDiag.Cred")) { 66 | Write-Warning "You have not created an XML File to hold the API Key or provided the API Key as a parameter 67 | You can export the key to an XML file using Get-Credential | Export-CliXml -Path `"`${env:\userprofile}\SQLDiag.Cred`" 68 | You can get a key by following the steps here https://ecsapi.portal.azure-api.net/ " 69 | break 70 | } 71 | else { 72 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "Get the APIKey from ${env:\userprofile}\SQLDiag.Cred ")) { 73 | $APIKey = (Import-Clixml -Path "${env:\userprofile}\SQLDiag.Cred").GetNetworkCredential().Password 74 | } 75 | Write-Verbose -Message "Using the APIKEY $APIKey" 76 | } 77 | } 78 | 79 | if ($file.GetType() -eq [string]) { 80 | Write-Verbose "Getting File Information about $file" 81 | try { 82 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "Get information about $File")) { 83 | $File = Get-SQLDiagDumpFile -file $File 84 | } 85 | Write-Verbose "Got File Information FileName = $($File.FullName) File Size = $($file.Length)" 86 | } 87 | catch { 88 | Write-Warning -Message "Failed to get File Information about $File - Quitting" 89 | break 90 | } 91 | } 92 | } 93 | Process { 94 | try { 95 | Write-Verbose "Get the UploadURL from the API" 96 | if ($PSCmdlet.ShouldProcess($File.FullName, "Get the UploadURL from the API")) { 97 | $getUploadURLSplat = @{ 98 | File = $File 99 | MachineGUID = $MachineGUID 100 | Region = $Region 101 | Email = $Email 102 | APIKey = $APIKey 103 | } 104 | $UploadResponse = Get-UploadURL @getUploadURLSplat 105 | Write-Verbose "Got the UploadURL $($UploadResponse.UploadURL) for RequestID $($UploadResponse.RequestID) from the API" 106 | } 107 | } 108 | catch { 109 | Write-Warning -Message "Failed to get the Upload URL for the File $($File.FullPath)" 110 | break 111 | } 112 | $RequestID = $UploadResponse.RequestID 113 | $UploadURL = $UploadResponse.UploadURL 114 | try { 115 | Write-verbose -Message "Upload the File to storage for analysis" 116 | if ($PSCmdlet.ShouldProcess($File.FullName, "Upload the File to storage for analysis")) { 117 | $startFileUploadSplat = @{ 118 | Uri = $UploadURL 119 | File = $File 120 | } 121 | Start-FileUpload @startFileUploadSplat 122 | } 123 | } 124 | catch { 125 | Write-Warning -Message "Failed to upload the File $($File.FullName) for RequestID $RequestID" 126 | break 127 | } 128 | Write-Verbose -Message "Intiating Analysis of Dump File $($File.FullName)" 129 | try { 130 | if ($PSCmdlet.ShouldProcess($File.FullName, "Intiating Analysis of Dump File")) { 131 | 132 | $startFileAnalysisSplat = @{ 133 | MachineGUID = $MachineGUID 134 | RequestID = $RequestID 135 | APIKey = $ApiKey 136 | } 137 | $response = Start-FileAnalysis @startFileAnalysisSplat 138 | } 139 | } 140 | catch { 141 | Write-Warning -Message "File analysis Initiation for $File Failed" 142 | break 143 | } 144 | } 145 | End { 146 | 147 | If ($response) { 148 | Write-Verbose "Successfully invoked Analysis of file $($File.FullName) with RequestID $RequestID" 149 | } 150 | else { 151 | Write-Warning "Failed to Invoke analysis of File $File.FullName" 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /header-mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: SQL Diag API 2 | repo_url: https://github.com/SQLDBAWithABeard/SQLDiagAPI 3 | site_author: The Beard 4 | edit_uri: edit/master/docs/ 5 | theme: readthedocs 6 | copyright: "MIT license" 7 | pages: 8 | - Home: index.md -------------------------------------------------------------------------------- /install.md: -------------------------------------------------------------------------------- 1 | # Installing SQLDiagAPI 2 | 3 | The SQLDIagAPI module is avaialble on the PowerShell Gallery and can be installed using 4 | 5 | Install-Module SQLDiagAPI 6 | 7 | if your user account is not an administrator on your machine you can install using 8 | 9 | Install-Module SQLDiagAPI -Scope CurrentUser 10 | 11 | You can also install the module using the [install.ps1](install.ps1) script which will download and install the module to your user profile. 12 | 13 | All you need to do is to run this code 14 | 15 | Invoke-Expression (Invoke-WebRequest -UseBasicParsing https://git.io/vQCNp) 16 | 17 | # In the future you will be able to install SQLDiagAPI from the Powershell Gallery using 18 | Find-Module SQLDiagAPI | Install-Module 19 | Import-Module SQLDiagAPI 20 | -------------------------------------------------------------------------------- /install.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param ( 3 | ) 4 | 5 | ## All thanks to the girl with the hair @cl 6 | 7 | Remove-Module -Name SQLDiagAPI -ErrorAction SilentlyContinue 8 | 9 | $path = "$HOME\Documents\WindowsPowerShell\Modules\SQLDiagAPI" 10 | $temp = ([System.IO.Path]::GetTempPath()).TrimEnd("\") 11 | $zipfile = "$temp\SQLDiagAPI.zip" 12 | $url = 'https://github.com/SQLDBAWithABeard/SQLDiagAPI/archive/master.zip' 13 | 14 | if (!(Test-Path -Path $path)) { 15 | try { 16 | Write-Output "Creating directory: $path" 17 | New-Item -Path $path -ItemType Directory | Out-Null 18 | } 19 | catch { 20 | throw "Can't create $Path. You may need to Run as Administrator" 21 | } 22 | } 23 | else { 24 | try { 25 | Write-Output "Deleting previously installed module" 26 | Remove-Item -Path "$path\*" -Force -Recurse 27 | } 28 | catch { 29 | throw "Can't delete $Path. You may need to Run as Administrator" 30 | } 31 | } 32 | 33 | Write-Output "Downloading archive from github" 34 | try { 35 | Invoke-WebRequest $url -OutFile $zipfile 36 | } 37 | catch { 38 | #try with default proxy and usersettings 39 | Write-Output "Probably using a proxy for internet access, trying default proxy settings" 40 | (New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials 41 | Invoke-WebRequest $url -OutFile $zipfile 42 | } 43 | 44 | # Unblock if there's a block 45 | Unblock-File $zipfile -ErrorAction SilentlyContinue 46 | 47 | Write-Output "Unzipping" 48 | 49 | # Keep it backwards compatible 50 | $shell = New-Object -ComObject Shell.Application 51 | $zipPackage = $shell.NameSpace($zipfile) 52 | $destinationFolder = $shell.NameSpace($temp) 53 | $destinationFolder.CopyHere($zipPackage.Items()) 54 | 55 | Write-Output "Cleaning up" 56 | Move-Item -Path "$temp\SQLDiagAPI-master\*" $path 57 | Remove-Item -Path "$temp\SQLDiagAPI-master" 58 | Remove-Item -Path $zipfile 59 | 60 | Write-Output "Done! Please report any bugs to https://github.com/SQLDBAWithABeard/SQLDiagAPI/issues." 61 | if ((Get-Command -Module SQLDiagAPI).count -eq 0) { Import-Module "$path\SQLDiagAPI.psd1" -Force } 62 | Get-Command -Module SQLDiagAPI 63 | Write-Output "`n`nIf you experience any function missing errors after update, please restart PowerShell or reload your profile." -------------------------------------------------------------------------------- /internal/Get-MachineGuid.ps1: -------------------------------------------------------------------------------- 1 | function Get-MachineGUID { 2 | ############################## 3 | #.SYNOPSIS 4 | # Internal function to get hte mcahine guid for identifying the machine to the API 5 | # 6 | ############################## 7 | [cmdletbinding(SupportsShouldProcess = $true)] 8 | param() 9 | try { 10 | Write-Verbose -Message "Reading the registry for the machine guid" 11 | if ($PSCmdlet.ShouldProcess($Env:COMPUTERNAME, "Reading the registry for the machine guid")) { 12 | if(Test-Path 'HKLM:\\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Sever\Extensions\ECS'){ 13 | (Get-ItemProperty 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Sever\Extensions\ECS' -Name SsmsExtension).SsmsExtension 14 | Write-Verbose -Message "Got the SSMS machine guid from the registry at HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Sever\Extensions\ECS" 15 | } 16 | elseif (Test-Path HKLM:\SOFTWARE\Microsoft\Microsoft SQL Sever\Extensions\ECS\SsmsExtension){ 17 | (Get-ItemProperty 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Sever\Extensions\ECS\SsmsExtension' -Name SsmsExtension).SsmsExtension 18 | Write-Verbose -Message "Got the SSMS machine guid from the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Sever\Extensions\ECS\SsmsExtension" 19 | } 20 | else{ 21 | (Get-ItemProperty registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\ -Name MachineGuid).MachineGUID 22 | Write-Verbose -Message "Got the general machine guid from the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\" 23 | } 24 | Write-Verbose -Message "Got the machine guid from the registry" 25 | } 26 | } 27 | catch { 28 | Write-Warning "Failed to get Machine GUID from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\" 29 | } 30 | } -------------------------------------------------------------------------------- /internal/Get-UploadURL.ps1: -------------------------------------------------------------------------------- 1 | ############################## 2 | #.SYNOPSIS 3 | # Internal Function to return the URL from the API for uploading the file 4 | # 5 | ############################## 6 | function Get-UploadURL{ 7 | [cmdletbinding(SupportsShouldProcess = $true)] 8 | param( 9 | [parameter(ValueFromPipelineByPropertyName = $true, 10 | ValueFromPipeline = $true, 11 | Mandatory = $true)] 12 | [string]$APIKey, 13 | [parameter(ValueFromPipelineByPropertyName = $true, 14 | ValueFromPipeline = $true, 15 | Mandatory = $true)] 16 | [string]$MachineGUID, 17 | [parameter(ValueFromPipelineByPropertyName = $true, 18 | ValueFromPipeline = $true, 19 | Mandatory = $true)] 20 | [object]$File, 21 | [parameter(ValueFromPipelineByPropertyName = $true, 22 | ValueFromPipeline = $true, 23 | Mandatory = $true)] 24 | [string]$Region, 25 | [parameter(ValueFromPipelineByPropertyName = $true, 26 | ValueFromPipeline = $true, 27 | Mandatory = $false)] 28 | [string]$Email 29 | ) 30 | $size = $File.Length/1MB 31 | $UploadAPIURL = 'https://ecsapi.azure-api.net/DiagnosticAnalysis/SQLAnalysis/GetUploadUrl' 32 | $headers = @{ "Ocp-Apim-Subscription-Key" = $apiKey } 33 | $Body = 34 | @{ 35 | clientId = $MachineGUID 36 | fileName = $File.FullName 37 | region = $Region 38 | notificationEmail = $Email 39 | metadata = @{ 40 | fileSize = "$size MB" 41 | } 42 | } | ConvertTo-Json 43 | 44 | Write-Verbose -Message "Getting the Upload URL for $($File.FullName) with GetUploadURL API $UploadAPIURL" 45 | if ($PSCmdlet.ShouldProcess('SQL Analysis GetUploadURL', "Getting the Upload URL for $File with $UploadAPIURL")) { 46 | try { 47 | $invokeRestMethodSplat = @{ 48 | Uri = $UploadAPIURL 49 | ContentType = "application/json" 50 | Headers = $headers 51 | Method = 'Post' 52 | ErrorAction = 'Stop' 53 | Body = $Body 54 | } 55 | $UploadResponse = Invoke-RestMethod @invokeRestMethodSplat 56 | Write-Verbose -Message "Got the Upload URL $UploadResponse" 57 | } 58 | catch { 59 | Write-Warning -Message "Failed to get the Upload URL from API $UploadAPiURL" 60 | break 61 | } 62 | } 63 | 64 | $UploadResponse 65 | } -------------------------------------------------------------------------------- /internal/ShowDialog.ps1: -------------------------------------------------------------------------------- 1 | function ShowDialog { 2 | [void]$Picker.ShowDialog() 3 | } -------------------------------------------------------------------------------- /internal/Start-FileAnalysis.ps1: -------------------------------------------------------------------------------- 1 | ############################## 2 | #.SYNOPSIS 3 | #Starts the dump analysis 4 | # 5 | # 6 | #.PARAMETER ApiKey 7 | # The APIKey used to authenticate against the API. You can get one from https://ecsapi.portal.azure-api.net/ 8 | # 9 | #.PARAMETER MachineGUID 10 | # GUID from Get-MachineGuid 11 | # 12 | #.PARAMETER RequestID 13 | # RequestID to start analysis for 14 | # 15 | #.NOTES 16 | # AUTHOR Rob Sewell @SQLDBAWithBeard https://sqldbawithabeard.com 17 | # DATE 11/07/2017 18 | ############################## 19 | function Start-FileAnalysis { 20 | [cmdletbinding(SupportsShouldProcess = $true)] 21 | param( 22 | [parameter(ValueFromPipelineByPropertyName = $true, 23 | ValueFromPipeline = $true, 24 | Mandatory = $false)] 25 | [string]$ApiKey, 26 | [parameter(ValueFromPipelineByPropertyName = $true, 27 | ValueFromPipeline = $true, 28 | Mandatory = $false)] 29 | [string]$MachineGUID, 30 | [parameter(ValueFromPipelineByPropertyName = $true, 31 | ValueFromPipeline = $true, 32 | Mandatory = $false)] 33 | [string]$RequestID 34 | ) 35 | Begin { 36 | $InitiateAnalysisAPIURL = 'https://ecsapi.azure-api.net/DiagnosticAnalysis/SQLAnalysis/InitiateAnalysis' 37 | 38 | $headers = @{ "Ocp-Apim-Subscription-Key" = $apiKey } 39 | $Body = 40 | @{ 41 | clientId = $MachineGUID 42 | RequestID = $RequestID 43 | } | ConvertTo-Json 44 | } 45 | Process { 46 | Write-Verbose -Message "Intiating Analysis of Dump File $File" 47 | if ($PSCmdlet.ShouldProcess('SQL Analysis Initiate Analysis', "Intiating Analysis of Dump File $File with $InitiateAnalysisAPIURL")) { 48 | try { 49 | $invokeRestMethodSplat = @{ 50 | Body = $Body 51 | Uri = $InitiateAnalysisAPIURL 52 | Method = 'Post' 53 | Headers = $headers 54 | ErrorAction = 'Stop' 55 | ContentType = "application/json" 56 | } 57 | $response = Invoke-RestMethod @invokeRestMethodSplat 58 | Write-Verbose -Message "Intiated Analysis of Dump File $File" 59 | } 60 | catch { 61 | Write-Warning -Message "Failed to initiate analysis of $Fiel with API $InitiateAnalysisAPIURL" 62 | break 63 | } 64 | } 65 | } 66 | End { 67 | $response 68 | } 69 | } -------------------------------------------------------------------------------- /internal/Start-FileUpload.ps1: -------------------------------------------------------------------------------- 1 | ############################## 2 | #.SYNOPSIS 3 | # Internal Function to upload file 4 | # 5 | #.PARAMETER Uri 6 | # URL from Get-UploadURL 7 | # 8 | #.PARAMETER File 9 | # File Object 10 | ############################## 11 | function Start-FileUpload { 12 | [cmdletbinding(SupportsShouldProcess = $true)] 13 | param( 14 | [parameter(ValueFromPipelineByPropertyName = $true, 15 | ValueFromPipeline = $true, 16 | Mandatory = $false)] 17 | [string]$Uri, 18 | [parameter(ValueFromPipelineByPropertyName = $true, 19 | ValueFromPipeline = $true, 20 | Mandatory = $false)] 21 | [object]$File) 22 | Write-Warning "There is no progress bar at present on the file upload" 23 | if (!(Get-Module Azure.Storage -ListAvailable)) { 24 | 25 | Write-Warning -Message "This requires the Azure.Storage Module - Please run Install-Module Azure.Storage -Scope CurrentUser to install from the PowerShell Gallery" 26 | } 27 | else { 28 | Write-Verbose -Message "Import Azure.Storage Module" 29 | try { 30 | if ($PSCmdlet.ShouldProcess("Azure.Storage Module", "Importing")) { 31 | Import-Module -Name Azure.Storage 32 | } 33 | } 34 | catch { 35 | Write-Warning -Message "Failed to import Azure.Storage module - quitting" 36 | break 37 | } 38 | } 39 | <# 40 | if we could use async upload then use this but I cannot get it to work 41 | $blobContent = System.IO.File.ReadAllBytes($file.FullName) 42 | $blob = New-Object Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob ($uri) 43 | $Blob.UploadFromByteArrayAsync($blobContent, 0, $File.Size) 44 | #> 45 | $blob = New-Object Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob ($uri) 46 | try { 47 | Write-verbose -Message "Uploading the file $File for analysis" 48 | if ($PSCmdlet.ShouldProcess($File.FullName, "Uploading the File for analysis")) { 49 | $blob.UploadFromFile($file.FullName, $null, $null, $null) 50 | } 51 | } 52 | catch { 53 | Write-Warning -Message "Failed to upload File $($File.FullName)" 54 | break 55 | } 56 | } -------------------------------------------------------------------------------- /internal/invoke-FilePicker.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-FilePicker { 2 | ############################## 3 | #.SYNOPSIS 4 | # Internal command to open a file browser and select a mdmp file and return Path and Size in MB 5 | ############################## 6 | [cmdletbinding(SupportsShouldProcess = $true)] 7 | param() 8 | try { 9 | Write-Verbose -message "Loading Forms assembly" 10 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "Loading the forms assembly ")) { 11 | Add-Type -AssemblyName System.Windows.Forms 12 | } 13 | } 14 | catch { 15 | Write-Warning -Message "Failed to load forms assembly" 16 | break 17 | } 18 | 19 | try { 20 | Write-Verbose -message "Creating the File picker object" 21 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "Creating the File picker object")) { 22 | $Picker = New-Object System.Windows.Forms.OpenFileDialog -Property @{ 23 | Multiselect = $false # Multiple files can be chosen 24 | Filter = 'SQL Server Dump File (*.mdmp)|*.mdmp' 25 | } 26 | } 27 | } 28 | catch { 29 | Write-Warning -Message "Failed to create the File Picker Object" 30 | break 31 | } 32 | 33 | try { 34 | Write-Verbose -message "Show the File picker dialogue" 35 | if ($PSCmdlet.ShouldProcess($env:COMPUTERNAME, "show the file picker dialogue")) { 36 | ShowDialog 37 | } 38 | } 39 | catch { 40 | Write-Warning -Message "Failed to open File picker dialogue" 41 | break 42 | } 43 | 44 | try { 45 | Write-Verbose -message "Getting information about the file $Picker.FullName" 46 | if ($PSCmdlet.ShouldProcess($Picker.FullName, "Getting information about the file ")) { 47 | $File = Get-Item $Picker.FileName 48 | } 49 | } 50 | catch { 51 | Write-Warning -Message "Failed to get information about $($Picker.FullName)" 52 | break 53 | } 54 | try { 55 | Write-Verbose -message "Returning the file object" 56 | if ($PSCmdlet.ShouldProcess($File.FullName, "Returning the file object ")) { 57 | [PSCustomObject] @{ 58 | Fullname = $File.Fullname 59 | Length = $File.Length 60 | } 61 | } 62 | } 63 | catch { 64 | Write-Warning -Message "Failed to return the file object" 65 | break 66 | } 67 | } 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: SQL Diag API 2 | repo_url: https://github.com/SQLDBAWithABeard/SQLDiagAPI 3 | site_author: The Beard 4 | edit_uri: edit/master/docs/ 5 | theme: readthedocs 6 | copyright: "MIT license" 7 | pages: 8 | - Home: index.md 9 | - Functions: 10 | - Get-SQLDiagAnalysis: functions/Get-SQLDiagAnalysis.md 11 | - Get-SQLDiagAnalysisHistory: functions/Get-SQLDiagAnalysisHistory.md 12 | - Get-SQLDiagDumpFile: functions/Get-SQLDiagDumpFile.md 13 | - Get-SQLDiagFeature: functions/Get-SQLDiagFeature.md 14 | - Get-SQLDiagFix: functions/Get-SQLDiagFix.md 15 | - Get-SQLDiagLatestAnalysis: functions/Get-SQLDiagLatestAnalysis.md 16 | - Get-SQLDiagLatestCU: functions/Get-SQLDiagLatestCU.md 17 | - Get-SQLDiagProduct: functions/Get-SQLDiagProduct.md 18 | - Get-SQLDiagRecommendations: functions/Get-SQLDiagRecommendations.md 19 | - Get-SQLDiagSupportedRegions: functions/Get-SQLDiagSupportedRegions.md 20 | - Invoke-SQLDiagDumpAnalysis: functions/Invoke-SQLDiagDumpAnalysis.md 21 | 22 | -------------------------------------------------------------------------------- /tests/Feature.Tests.ps1: -------------------------------------------------------------------------------- 1 | $script:ModuleName = 'SQLDiagAPI' 2 | # Removes all versions of the module from the session before importing 3 | Get-Module $ModuleName | Remove-Module 4 | $ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path 5 | # For tests in .\Tests subdirectory 6 | if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') { 7 | $ModuleBase = Split-Path $ModuleBase -Parent 8 | } 9 | 10 | Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop | Out-Null 11 | Describe "Get-" -Tags Build { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tests/Help.Exceptions.ps1: -------------------------------------------------------------------------------- 1 | PSUseSingularNouns 2 | Unit.Tests.ps1 3 | 4 | -------------------------------------------------------------------------------- /tests/Help.Tests.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .NOTES 3 | =========================================================================== 4 | Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.119 5 | Created on: 4/12/2016 1:11 PM 6 | Created by: June Blender 7 | Organization: SAPIEN Technologies, Inc 8 | Filename: *.Help.Tests.ps1 9 | =========================================================================== 10 | .DESCRIPTION 11 | To test help for the commands in a module, place this file in the module folder. 12 | To test any module from any path, use https://github.com/juneb/PesterTDD/Module.Help.Tests.ps1 13 | #> 14 | 15 | $ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path 16 | $FunctionHelpTestExceptions = Get-Content -Path "$ModuleBase\Help.Exceptions.ps1" 17 | 18 | # For tests in .\Tests subdirectory 19 | if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') { 20 | $ModuleBase = Split-Path $ModuleBase -Parent 21 | } 22 | 23 | # Handles modules in version directories 24 | $leaf = Split-Path $ModuleBase -Leaf 25 | $parent = Split-Path $ModuleBase -Parent 26 | $parsedVersion = $null 27 | if ([System.Version]::TryParse($leaf, [ref]$parsedVersion)) { 28 | $ModuleName = Split-Path $parent -Leaf 29 | } 30 | else { 31 | $ModuleName = $leaf 32 | } 33 | 34 | # Removes all versions of the module from the session before importing 35 | Get-Module $ModuleName | Remove-Module 36 | 37 | # Because ModuleBase includes version number, this imports the required version 38 | # of the module 39 | $Module = Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop 40 | $commands = Get-Command -Module $module -CommandType Cmdlet, Function, Workflow # Not alias 41 | 42 | 43 | ## When testing help, remember that help is cached at the beginning of each session. 44 | ## To test, restart session. 45 | 46 | foreach ($command in $commands) { 47 | $commandName = $command.Name 48 | 49 | # Skip all functions that are on the exclusions list 50 | if ($FunctionHelpTestExceptions -contains $commandName) { continue } 51 | 52 | # The module-qualified command fails on Microsoft.PowerShell.Archive cmdlets 53 | $Help = Get-Help $commandName -ErrorAction SilentlyContinue 54 | 55 | Describe "Test help for $commandName" -Tag Help { 56 | 57 | # If help is not found, synopsis in auto-generated help is the syntax diagram 58 | It "should not be auto-generated" { 59 | $Help.Synopsis | Should Not BeLike '*`[``]*' 60 | } 61 | 62 | # Should be a description for every function 63 | It "gets description for $commandName" { 64 | $Help.Description | Should Not BeNullOrEmpty 65 | } 66 | 67 | # Should be at least one example 68 | It "gets example code from $commandName" { 69 | ($Help.Examples.Example | Select-Object -First 1).Code | Should Not BeNullOrEmpty 70 | } 71 | 72 | # Should be at least one example description 73 | It "gets example help from $commandName" { 74 | ($Help.Examples.Example.Remarks | Select-Object -First 1).Text | Should Not BeNullOrEmpty 75 | } 76 | 77 | Context "Test parameter help for $commandName" { 78 | 79 | $Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable', 80 | 'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable', 'Confirm', 'Whatif' 81 | 82 | $parameters = $command.ParameterSets.Parameters | Sort-Object -Property Name -Unique | Where-Object Name -notin $common 83 | $parameterNames = $parameters.Name 84 | $HelpParameterNames = $Help.Parameters.Parameter.Name | Sort-Object -Unique 85 | 86 | foreach ($parameter in $parameters) { 87 | $parameterName = $parameter.Name 88 | $parameterHelp = $Help.parameters.parameter | Where-Object Name -EQ $parameterName 89 | 90 | # Should be a description for every parameter 91 | It "gets help for parameter: $parameterName : in $commandName" { 92 | $parameterHelp.Description.Text | Should Not BeNullOrEmpty 93 | } 94 | 95 | # Required value in Help should match IsMandatory property of parameter 96 | It "help for $parameterName parameter in $commandName has correct Mandatory value" { 97 | $codeMandatory = $parameter.IsMandatory.toString() 98 | $parameterHelp.Required | Should Be $codeMandatory 99 | } 100 | 101 | # Parameter type in Help should match code 102 | It "help for $commandName has correct parameter type for $parameterName" { 103 | $codeType = $parameter.ParameterType.Name 104 | # To avoid calling Trim method on a null object. 105 | $helpType = if ($parameterHelp.parameterValue) { $parameterHelp.parameterValue.Trim() } 106 | $helpType | Should be $codeType 107 | } 108 | } 109 | 110 | foreach ($helpParm in $HelpParameterNames.Where{$_ -notin ('Confirm', 'Whatif')}) { 111 | # Shouldn't find extra parameters in help. 112 | It "finds help parameter in code: $helpParm" { 113 | $helpParm -in $parameterNames | Should Be $true 114 | } 115 | } 116 | } 117 | } 118 | } 119 | 120 | -------------------------------------------------------------------------------- /tests/Project.Tests.ps1: -------------------------------------------------------------------------------- 1 | $script:ModuleName = 'SQLDiagAPI' 2 | # Removes all versions of the module from the session before importing 3 | Get-Module $ModuleName | Remove-Module 4 | $ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path 5 | $FunctionHelpTestExceptions = Get-Content -Path "$ModuleBase\Help.Exceptions.ps1" 6 | # For tests in .\Tests subdirectory 7 | if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') { 8 | $ModuleBase = Split-Path $ModuleBase -Parent 9 | } 10 | Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop | Out-Null 11 | Describe "PSScriptAnalyzer rule-sets" -Tag Build, ScriptAnalyzer { 12 | 13 | $Rules = Get-ScriptAnalyzerRule 14 | $scripts = Get-ChildItem $ModuleBase -Include *.ps1, *.psm1, *.psd1 -Recurse | Where-Object fullname -notmatch 'classes' 15 | 16 | foreach ( $Script in $scripts ) 17 | { 18 | Context "Script '$($script.FullName)'" { 19 | if ($FunctionHelpTestExceptions -contains $Script.Name) { continue } 20 | foreach ( $rule in $rules) 21 | { 22 | # Skip all rules that are on the exclusions list 23 | if ($FunctionHelpTestExceptions -contains $rule.RuleName) { continue } 24 | It "Rule [$rule]" { 25 | 26 | (Invoke-ScriptAnalyzer -Path $script.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0 27 | } 28 | } 29 | } 30 | } 31 | } 32 | 33 | 34 | Describe "General project validation: $moduleName" -Tags Build { 35 | BeforeAll { 36 | Get-Module $ModuleName | Remove-Module 37 | } 38 | 39 | It "Module '$moduleName' can import cleanly" { 40 | {Import-Module $ModuleBase\$ModuleName.psd1 -force } | Should Not Throw 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Regression.Tests.ps1: -------------------------------------------------------------------------------- 1 | $script:ModuleName = 'SQLDiagAPI' 2 | # Removes all versions of the module from the session before importing 3 | Get-Module $ModuleName | Remove-Module 4 | $ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path 5 | # For tests in .\Tests subdirectory 6 | if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') { 7 | $ModuleBase = Split-Path $ModuleBase -Parent 8 | } 9 | 10 | Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop | Out-Null 11 | Describe "Regression tests" -Tag Build, Regression { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tests/Unit.Tests.ps1: -------------------------------------------------------------------------------- 1 | $script:ModuleName = 'SQLDiagAPI' 2 | # Removes all versions of the module from the session before importing 3 | Get-Module $ModuleName | Remove-Module 4 | $ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path 5 | # For tests in .\Tests subdirectory 6 | if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') { 7 | $ModuleBase = Split-Path $ModuleBase -Parent 8 | } 9 | 10 | Import-Module $ModuleBase\$ModuleName.psd1 -ErrorAction Stop #| Out-Null 11 | InModuleScope -ModuleName SQLDiagAPI { 12 | Describe "Get-SQLDiagRecommendations" -Tags Build , Unit, Recommendations { 13 | 14 | Context "Requirements" { 15 | BeforeAll { 16 | Mock Test-Path {$false} 17 | Mock Write-Warning {"Warning"} 18 | } 19 | It "Should throw a warning if there is no API Key XML File and the APIKey Parameter is not used" { 20 | Get-SQLDiagRecommendations -ErrorAction SilentlyContinue | Should Be "Warning" 21 | } 22 | It 'Checks the Mock was called for Test-Path' { 23 | $assertMockParams = @{ 24 | 'CommandName' = 'Test-Path' 25 | 'Times' = 1 26 | 'Exactly' = $true 27 | } 28 | Assert-MockCalled @assertMockParams 29 | } 30 | It 'Checks the Mock was called for Write-Warning' { 31 | $assertMockParams = @{ 32 | 'CommandName' = 'Write-Warning' 33 | 'Times' = 1 34 | 'Exactly' = $true 35 | } 36 | Assert-MockCalled @assertMockParams 37 | } 38 | 39 | } 40 | Context "Input" { 41 | 42 | } 43 | Context "Execution" { 44 | It "Returns a warning if unable to get Machine GUID" { 45 | Mock Get-MachineGUID {} -Verifiable 46 | Mock Write-Warning {"Warning"} -Verifiable 47 | Get-SQLDiagRecommendations -APIKey dummykey | Should Be "Warning" 48 | Assert-VerifiableMocks 49 | } 50 | 51 | } 52 | Context "Output" { 53 | $Results = (Get-Content $PSScriptRoot\json\recommendations.JSON) -join "`n" | ConvertFrom-Json 54 | Mock Invoke-WebRequest {$Results} 55 | It "Should return the correct results" { 56 | Compare-Object (Get-SQLDiagRecommendations) $Results | Should BeNullOrEmpty 57 | } 58 | } 59 | } 60 | 61 | Describe "Get-SQLDiagLatestCU" -Tags Build , Unit, LatestCUs { 62 | BeforeAll { 63 | $Recommendations = (Get-Content $PSScriptRoot\json\recommendations.JSON) -join "`n" | ConvertFrom-Json 64 | Mock Get-SQLDiagRecommendations {$Recommendations} 65 | Mock Write-Warning {"warning"} 66 | } 67 | Context "Input" { 68 | It "Accepts Recommendations input via Pipeline" { 69 | Get-SQLDiagRecommendations | Get-SQLDiagLatestCU -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 70 | {Get-SQLDiagRecommendations | Get-SQLDiagLatestCU} | Should Not Throw 71 | } 72 | It "Accepts Recommendations input via Parameter" { 73 | Get-SQLDiagLatestCU -Recommendations $Recommendations -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 74 | } 75 | It "Accepts Product via Parameter" { 76 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' | Should Not BeNullOrEmpty 77 | {Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' } | Should Not throw 78 | } 79 | It "Accepts Product without a Parameter name" { 80 | Get-SQLDiagLatestCU 'SQL Server 2012 SP3' | Should Not BeNullOrEmpty 81 | {Get-SQLDiagLatestCU 'SQL Server 2012 SP3' } | Should Not throw 82 | } 83 | It "Accepts single product from the pipeline" { 84 | Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU | Should Not BeNullOrEmpty 85 | {Get-SQLDiagProduct 2012 | Get-SQLDiagLatestCU} | Should Not throw 86 | } 87 | It "Accepts multiple products from the pipeline" { 88 | Get-SQLDiagProduct 2014 | Get-SQLDiagLatestCU | Should Not BeNullOrEmpty 89 | {Get-SQLDiagProduct 2014 | Get-SQLDiagLatestCU} | Should Not throw 90 | } 91 | It "Learnmore switch throws a warning if no Product specified" { 92 | Get-SQLDiagLatestCU -LearnMore | Should Be "warning" 93 | } 94 | It "Learnmore switch throws a warning if multiple Products specified" { 95 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3', 'SQL Server 2014 SP1' -LearnMore | Should Be "warning" 96 | } 97 | It "Download switch throws a warning if no Product specified" { 98 | Get-SQLDiagLatestCU -Download | Should Be "warning" 99 | } 100 | It "Download switch throws a warning if multiple Products specified" { 101 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3', 'SQL Server 2014 SP1' -Download | Should Be "warning" 102 | } 103 | It 'Checks the Mock was called for Write-Warning' { 104 | $assertMockParams = @{ 105 | 'CommandName' = 'Write-Warning' 106 | 'Times' = 4 107 | 'Exactly' = $true 108 | } 109 | Assert-MockCalled @assertMockParams 110 | } 111 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 112 | $assertMockParams = @{ 113 | 'CommandName' = 'Get-SQLDiagRecommendations' 114 | 'Times' = 36 115 | 'Exactly' = $true 116 | } 117 | Assert-MockCalled @assertMockParams 118 | } 119 | } 120 | Context "Execution" { 121 | 122 | } 123 | Context "Output" { 124 | BeforeAll { 125 | $NoProductParameters = (Get-Content $PSScriptRoot\json\LatestCuProductDefault.JSON) -join "`n" | ConvertFrom-Json 126 | Mock Start-Process {"browser"} 127 | } 128 | It "Returns expected values with no Product Parameter" { 129 | 130 | Compare-Object (Get-SQLDiagLatestCU -Recommendations (Get-SQLDiagRecommendations)) $NoProductParameters | Should BeNullOrEmpty 131 | } 132 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3'}, 133 | @{ ProductName = 'SQL Server 2016 SP1'}, 134 | @{ ProductName = 'SQL Server 2016 RTM'}, 135 | @{ ProductName = 'SQL Server 2014 SP1'}, 136 | @{ ProductName = 'SQL Server 2014 SP2'} 137 | It "Should Return only the filtered Product CU for " -TestCases $TestCases { 138 | Param($ProductName) 139 | $Results = $NoProductParameters.Where{$_.Product -eq $ProductName} 140 | Compare-Object (Get-SQLDiagLatestCU -Recommendations (Get-SQLDiagRecommendations) -Product $ProductName) $Results |Should BeNullOrEmpty 141 | } 142 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1'}, 143 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM'}, 144 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1'}, 145 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1', 'SQL Server 2014 SP2'} 146 | It "Should Return only the filtered Product CU for multiple Products " -TestCases $TestCases { 147 | Param($ProductName) 148 | $Results = $NoProductParameters.Where{$_.Product -in $ProductName} 149 | Compare-Object (Get-SQLDiagLatestCU -Recommendations (Get-SQLDiagRecommendations) -Product $ProductName) $Results |Should BeNullOrEmpty 150 | } 151 | It "LearnMore switch opens a browser with a Product specified" { 152 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' -LearnMore | Should Be "browser" 153 | } 154 | It "Download switch opens a browser with a Product specified" { 155 | Get-SQLDiagLatestCU -Product 'SQL Server 2012 SP3' -Download | Should Be "browser" 156 | } 157 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 158 | $assertMockParams = @{ 159 | 'CommandName' = 'Get-SQLDiagRecommendations' 160 | 'Times' = 33 161 | 'Exactly' = $true 162 | } 163 | Assert-MockCalled @assertMockParams 164 | } 165 | It 'Checks the Mock was called for Start-Process' { 166 | $assertMockParams = @{ 167 | 'CommandName' = 'Start-Process' 168 | 'Times' = 2 169 | 'Exactly' = $true 170 | } 171 | Assert-MockCalled @assertMockParams 172 | } 173 | } 174 | } 175 | 176 | Describe "Get-SQLDiagProduct" -Tags Build , Unit, Product { 177 | BeforeAll { 178 | $Recommendations = (Get-Content $PSScriptRoot\json\recommendations.JSON) -join "`n" | ConvertFrom-Json 179 | Mock Get-SQLDiagRecommendations {$Recommendations} 180 | } 181 | Context "Input" { 182 | It "Uses the default value for Recommendations" { 183 | Get-SQLDiagProduct -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 184 | } 185 | It "Accepts Recommendations input via Pipeline" { 186 | Get-SQLDiagRecommendations | Get-SQLDiagProduct -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 187 | {Get-SQLDiagRecommendations | Get-SQLDiagProduct} | Should Not Throw 188 | } 189 | It "Accepts Recommendations input via Parameter" { 190 | Get-SQLDiagProduct -Recommendations $Recommendations -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 191 | } 192 | It "Accepts Product Search without a parameter name" { 193 | Get-SQLDiagProduct 2012 | Should Be "SQL Server 2012 SP3" 194 | } 195 | It "It accepts a string for Product" { 196 | {Get-SQLDiagRecommendations | Get-SQLDiagProduct -Product SQL} | Should Not Throw 197 | } 198 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 199 | $assertMockParams = @{ 200 | 'CommandName' = 'Get-SQLDiagRecommendations' 201 | 'Times' = 8 202 | 'Exactly' = $true 203 | } 204 | Assert-MockCalled @assertMockParams 205 | } 206 | 207 | } 208 | Context "Execution" { 209 | 210 | } 211 | Context "Output" { 212 | It "Returns the correct data without a product" { 213 | Compare-Object (Get-SQLDiagProduct) $Recommendations.Recommendations.Product | Should BeNullOrEmpty 214 | } 215 | It "Returns a single object for a search" { 216 | $Results = $Recommendations.Recommendations.Product.Where{$_ -like '*2012*'} 217 | Compare-Object (Get-SQLDiagRecommendations | Get-SQLDiagProduct -Product 2012) $results | Should BeNullOrEmpty 218 | } 219 | It "Returns multiple object for a search" { 220 | $Results = $Recommendations.Recommendations.Product.Where{$_ -like '*2014*'} 221 | Compare-Object (Get-SQLDiagRecommendations | Get-SQLDiagProduct -Product 2014) $results | Should BeNullOrEmpty 222 | } 223 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 224 | $assertMockParams = @{ 225 | 'CommandName' = 'Get-SQLDiagRecommendations' 226 | 'Times' = 5 227 | 'Exactly' = $true 228 | } 229 | Assert-MockCalled @assertMockParams 230 | } 231 | } 232 | } 233 | Describe "Get-SQLDiagFeature" -Tags Build , Unit, Feature { 234 | BeforeAll { 235 | $Recommendations = (Get-Content $PSScriptRoot\json\recommendations.JSON) -join "`n" | ConvertFrom-Json 236 | Mock Get-SQLDiagRecommendations {$Recommendations} 237 | } 238 | Context "Input" { 239 | It "Uses the default value for Recommendations" { 240 | Get-SQLDiagFeature -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 241 | } 242 | It "Accepts Recommendations input via Pipeline" { 243 | Get-SQLDiagRecommendations | Get-SQLDiagFeature -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 244 | {Get-SQLDiagRecommendations | Get-SQLDiagFeature} | Should Not Throw 245 | } 246 | It "Accepts Recommendations input via Parameter" { 247 | Get-SQLDiagFeature -Recommendations $Recommendations -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 248 | } 249 | It "Accepts Product via Parameter" { 250 | Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' | Should Not BeNullOrEmpty 251 | {Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' } | Should Not throw 252 | } 253 | It "Accepts single product from the pipeline" { 254 | Get-SQLDiagProduct 2012 | Get-SQLDiagFeature | Should Not BeNullOrEmpty 255 | {Get-SQLDiagProduct 2012 | Get-SQLDiagFeature} | Should Not throw 256 | } 257 | It "Accepts multiple products from the pipeline" { 258 | Get-SQLDiagProduct 2014 | Get-SQLDiagFeature | Should Not BeNullOrEmpty 259 | {Get-SQLDiagProduct 2014 | Get-SQLDiagFeature} | Should Not throw 260 | } 261 | It "Accepts Feature search by Parameter" { 262 | Get-SQLDiagFeature -Feature Always | Should Not BeNullOrEmpty 263 | {Get-SQLDiagFeature -Feature Always } | Should Not throw 264 | } 265 | It "Accepts Feature search by Parameter with Product by pipeline" { 266 | Get-SQLDiagProduct 2012 | Get-SQLDiagFeature -Feature Always | Should Not BeNullOrEmpty 267 | {Get-SQLDiagProduct 2012 |Get-SQLDiagFeature -Feature Always } | Should Not throw 268 | } 269 | It "Accepts Product and Feature search by Parameter" { 270 | Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' -Feature Always | Should Not BeNullOrEmpty 271 | {Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' -Feature Always } | Should Not throw 272 | } 273 | It "Accepts Product and Feature search without Parameter" { 274 | Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' Always | Should Not BeNullOrEmpty 275 | {Get-SQLDiagFeature -Product 'SQL Server 2012 SP3' Always } | Should Not throw 276 | } 277 | It "Accepts Feature search without Parameter with Product by pipeline" { 278 | Get-SQLDiagProduct 2012 | Get-SQLDiagFeature Always | Should Not BeNullOrEmpty 279 | {Get-SQLDiagProduct 2012 |Get-SQLDiagFeature Always } | Should Not throw 280 | } 281 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 282 | $assertMockParams = @{ 283 | 'CommandName' = 'Get-SQLDiagRecommendations' 284 | 'Times' = 47 285 | 'Exactly' = $true 286 | } 287 | Assert-MockCalled @assertMockParams 288 | } 289 | 290 | } 291 | Context "Execution" { 292 | 293 | } 294 | Context "Output" { 295 | 296 | It "With No parameter returns a unique list of features" { 297 | $Results = (Get-Content $PSScriptRoot\json\Features.JSON) -join "`n" | ConvertFrom-Json 298 | Compare-Object (Get-SQLDiagFeature) $results | Should BeNullOrEmpty 299 | } 300 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3'}, 301 | @{ ProductName = 'SQL Server 2016 SP1'}, 302 | @{ ProductName = 'SQL Server 2016 RTM'}, 303 | @{ ProductName = 'SQL Server 2014 SP1'}, 304 | @{ ProductName = 'SQL Server 2014 SP2'} 305 | It "Returns the features for a single product " -TestCases $TestCases { 306 | Param($ProductName) 307 | $Features = (Get-Content $PSScriptRoot\json\ProductFeatures.JSON) -join "`n" | ConvertFrom-Json 308 | $results = $features.Where{$_.Product -eq $ProductName}.Feature 309 | Compare-Object (Get-SQLDiagFeature -Product $ProductName) $results | Should BeNullOrEmpty 310 | } 311 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1'}, 312 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM'}, 313 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1'}, 314 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1', 'SQL Server 2014 SP2'} 315 | It "Should Return only the filtered features for multiple Products " -TestCases $TestCases { 316 | Param($ProductName) 317 | $Features = (Get-Content $PSScriptRoot\json\ProductFeatures.JSON) -join "`n" | ConvertFrom-Json 318 | $results = $features.Where{$_.Product -in $ProductName} | Select-Object Feature -Unique -ExpandProperty Feature 319 | Compare-Object (Get-SQLDiagFeature -Product $ProductName) $results | Should BeNullOrEmpty} 320 | It "Should return the correct result for a feature search without a product" { 321 | $Features = (Get-Content $PSScriptRoot\json\ProductFeatures.JSON) -join "`n" | ConvertFrom-Json 322 | $results = $features.Where{$_.Feature -like '*Al*'} | Select-Object Feature -Unique -ExpandProperty Feature 323 | Compare-Object (Get-SQLDiagFeature -Feature Al) $results | Should BeNullOrEmpty 324 | } 325 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3'}, 326 | @{ ProductName = 'SQL Server 2016 SP1'}, 327 | @{ ProductName = 'SQL Server 2016 RTM'}, 328 | @{ ProductName = 'SQL Server 2014 SP1'}, 329 | @{ ProductName = 'SQL Server 2014 SP2'} 330 | It "Should return the correct result for a feature search with a single product from the pipeline " -TestCases $TestCases { 331 | param($productname) 332 | $Features = (Get-Content $PSScriptRoot\json\ProductFeatures.JSON) -join "`n" | ConvertFrom-Json 333 | $results = $features.Where{$_.Product -in $ProductName -and $_.Feature -like '*Al*'} | Select-Object Feature -Unique -ExpandProperty Feature 334 | Compare-Object (Get-SQLDiagProduct $productname | Get-SQLDiagFeature -Feature Al) $results | Should BeNullOrEmpty 335 | } 336 | $TestCases = @{ ProductName = '2012'}, 337 | @{ ProductName = '2014'}, 338 | @{ ProductName = '2016'}, 339 | @{ ProductName = 'SP1'} 340 | It "Should Return the correct result for all features from the pipeline for multiple Products " -TestCases $TestCases { 341 | Param($ProductName) 342 | $Features = (Get-Content $PSScriptRoot\json\ProductFeatures.JSON) -join "`n" | ConvertFrom-Json 343 | $results = $features.Where{$_.Product -like "*$($ProductName)*" } | Select-Object Feature -Unique -ExpandProperty Feature 344 | Compare-Object (Get-SQLDiagProduct $productname | Get-SQLDiagFeature) $results | Should BeNullOrEmpty 345 | } 346 | $TestCases = @{ ProductName = '2012'}, 347 | @{ ProductName = '2014'}, 348 | @{ ProductName = '2016'}, 349 | @{ ProductName = 'SP1'} 350 | It "Should Return the correct result for a feature search from the pipeline for multiple Products " -TestCases $TestCases { 351 | Param($ProductName) 352 | $Features = (Get-Content $PSScriptRoot\json\ProductFeatures.JSON) -join "`n" | ConvertFrom-Json 353 | $results = $features.Where{$_.Product -like "*$($ProductName)*" -and $_.Feature -like '*Al*'} | Select-Object Feature -Unique -ExpandProperty Feature 354 | Compare-Object (Get-SQLDiagProduct $productname | Get-SQLDiagFeature -Feature Al) $results | Should BeNullOrEmpty 355 | } 356 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 357 | $assertMockParams = @{ 358 | 'CommandName' = 'Get-SQLDiagRecommendations' 359 | 'Times' = 75 360 | 'Exactly' = $true 361 | } 362 | Assert-MockCalled @assertMockParams 363 | } 364 | } 365 | } 366 | Describe "Get-SQLDiagFix" -Tags Build , Unit, Fix { 367 | BeforeAll { 368 | $Recommendations = (Get-Content $PSScriptRoot\json\recommendations.JSON) -join "`n" | ConvertFrom-Json 369 | Mock Get-SQLDiagRecommendations {$Recommendations} 370 | } 371 | 372 | Context "Input" { 373 | It "Uses the default value for Recommendations" { 374 | Get-SQLDiagFix -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 375 | } 376 | It "Accepts Recommendations input via Pipeline" { 377 | Get-SQLDiagRecommendations | Get-SQLDiagFix -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 378 | {Get-SQLDiagRecommendations | Get-SQLDiagFix} | Should Not Throw 379 | } 380 | It "Accepts Recommendations input via Parameter" { 381 | Get-SQLDiagFix -Recommendations $Recommendations -ErrorAction SilentlyContinue| Should Not Be NullOrEmpty 382 | } 383 | It "Accepts Product via Parameter" { 384 | Get-SQLDiagFix -Product 'SQL Server 2012 SP3' | Should Not BeNullOrEmpty 385 | {Get-SQLDiagFix -Product 'SQL Server 2012 SP3' } | Should Not throw 386 | } 387 | It "Accepts single product from the pipeline" { 388 | Get-SQLDiagProduct 2012 | Get-SQLDiagFix | Should Not BeNullOrEmpty 389 | {Get-SQLDiagProduct 2012 | Get-SQLDiagFix} | Should Not throw 390 | } 391 | It "Accepts multiple products from the pipeline" { 392 | Get-SQLDiagProduct 2014 | Get-SQLDiagFix | Should Not BeNullOrEmpty 393 | {Get-SQLDiagProduct 2014 | Get-SQLDiagFix} | Should Not throw 394 | } 395 | It "Accepts Feature via Parameter" { 396 | Get-SQLDiagFix -Feature 'Always On' | Should Not BeNullOrEmpty 397 | {Get-SQLDiagFix -Feature 'Always On' } | Should Not throw 398 | } 399 | It "Accepts Feature without a Parameter name" { 400 | Get-SQLDiagFix 'Always On' | Should Not BeNullOrEmpty 401 | {Get-SQLDiagFix 'Always On' } | Should Not throw 402 | } 403 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 404 | $assertMockParams = @{ 405 | 'CommandName' = 'Get-SQLDiagRecommendations' 406 | 'Times' = 29 407 | 'Exactly' = $true 408 | } 409 | Assert-MockCalled @assertMockParams 410 | } 411 | } 412 | Context "Execution" { 413 | 414 | } 415 | Context "Output" { 416 | BeforeAll { 417 | $Fixes = (Get-Content $PSScriptRoot\json\fix.JSON) -join "`n" | ConvertFrom-Json 418 | $Products = Get-SQLDiagProduct 419 | $Features = Get-SQLDiagFeature 420 | } 421 | It "returns all of the fixes with no parameter" { 422 | Compare-Object (Get-SQLDiagFix) $Fixes | Should BeNullOrEmpty 423 | } 424 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3'}, 425 | @{ ProductName = 'SQL Server 2016 SP1'}, 426 | @{ ProductName = 'SQL Server 2016 RTM'}, 427 | @{ ProductName = 'SQL Server 2014 SP1'}, 428 | @{ ProductName = 'SQL Server 2014 SP2'} 429 | It "Returns the correct results with a single product parameter " -TestCases $TestCases { 430 | param($productname) 431 | $results = $fixes.Where{$_.Product -in $ProductName} 432 | Compare-Object (Get-SQLDiagFix -Product $productname) $results | Should BeNullOrEmpty 433 | } 434 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3'}, 435 | @{ ProductName = 'SQL Server 2016 SP1'}, 436 | @{ ProductName = 'SQL Server 2016 RTM'}, 437 | @{ ProductName = 'SQL Server 2014 SP1'}, 438 | @{ ProductName = 'SQL Server 2014 SP2'} 439 | It "Returns the correct results with a single product from the pipeline " -TestCases $TestCases { 440 | param($productname) 441 | $results = $fixes.Where{$_.Product -in $ProductName} 442 | Compare-Object (Get-SQLDiagProduct -Product $productname | Get-SQLDiagFix ) $results | Should BeNullOrEmpty 443 | } 444 | $TestCases = @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1'}, 445 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM'}, 446 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1'}, 447 | @{ ProductName = 'SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1', 'SQL Server 2014 SP2'} 448 | It "Returns the correct results with multiple product parameter " -TestCases $TestCases { 449 | param($productname) 450 | $results = $fixes.Where{$_.Product -in $ProductName} 451 | Compare-Object (Get-SQLDiagFix -Product $productname) $results | Should BeNullOrEmpty 452 | } 453 | $TestCases = @{ ProductName = '2012'}, 454 | @{ ProductName = '2014'}, 455 | @{ ProductName = '2016'}, 456 | @{ ProductName = 'SP1'} 457 | It "Returns the correct results with multiple products from the pipeline " -TestCases $TestCases { 458 | param($productname) 459 | $Products = Get-SQLDiagProduct -Product $productname 460 | $results = $fixes.Where{$_.Product -in $Products} 461 | Compare-Object (Get-SQLDiagProduct -Product $productname | Get-SQLDiagFix ) $results | Should BeNullOrEmpty 462 | } 463 | $TestCases = @() 464 | $Features | Foreach-Object {$TestCases += @{Feature = $_}} 465 | It "Returns the correct results with a single feature " -TestCases $TestCases { 466 | param($Feature) 467 | $results = $fixes.Where{$_.Feature -in $Feature} 468 | Compare-Object (Get-SQLDiagFix -Feature $Feature) $results | Should BeNullOrEmpty 469 | } 470 | ## Generate 10 TestCases of a random number of Features 471 | $TestCases = @() 472 | $x = 10 473 | While ($x -gt 0) { 474 | ## We are testing multiples so we need at least 2 475 | $Number = Get-Random -Maximum $Features.Count -Minimum 2 476 | $Test = @() 477 | While ($Number -gt 0) { 478 | $Test += Get-Random $Features 479 | $Number -- 480 | } 481 | ## Need unique values 482 | $Test = $test | Select-Object -Unique 483 | $TestCases += @{Feature = $Test} 484 | $X -- 485 | } 486 | It "Returns the correct results with a multiple features " -TestCases $TestCases { 487 | param($Feature) 488 | $results = $fixes.Where{$_.Feature -in $Feature} 489 | Compare-Object (Get-SQLDiagFix -Feature $Feature) $results | Should BeNullOrEmpty 490 | } 491 | 492 | foreach ($Product in $Products) { 493 | $TestCases = @() 494 | $Features = Get-SQLDiagFeature -Product $Product 495 | $Features | Foreach-Object {$TestCases += @{Feature = $_}} 496 | It "Returns the correct results for a single product parameter $Product with a single feature " -TestCases $TestCases { 497 | param($Feature) 498 | $results = $fixes.Where{$_.Product -eq $product -and $_.Feature -in $Feature} 499 | Compare-Object (Get-SQLDiagFix -Product $Product -Feature $Feature) $results | Should BeNullOrEmpty 500 | } 501 | } 502 | foreach ($Product in $Products) { 503 | ## Generate 10 TestCases of a random number of Features 504 | $TestCases = @() 505 | $x = 10 506 | While ($x -gt 0) { 507 | ## We are testing multiples so we need at least 2 508 | $Number = Get-Random -Maximum $Features.Count -Minimum 2 509 | $Test = @() 510 | While ($Number -gt 0) { 511 | $Test += Get-Random $Features 512 | $Number -- 513 | } 514 | ## Need unique values 515 | $Test = $test | Select-Object -Unique 516 | $TestCases += @{Feature = $Test} 517 | $X -- 518 | } 519 | It "Returns the correct results for a single product parameter $Product with a multiple features " -TestCases $TestCases { 520 | param($Feature) 521 | $Test = (Get-SQLDiagFix -Product $Product -Feature $Feature) 522 | ## Annoyingly if there are no results Compare-Object bombs out even though it is correct 523 | ## This is a risky fix for that 524 | if ($Test) { 525 | $results = $fixes.Where{$_.Product -eq $product -and $_.Feature -in $Feature} 526 | Compare-Object $test $results | Should BeNullOrEmpty 527 | } 528 | } 529 | } 530 | $Products = @('SQL Server 2012 SP3', 'SQL Server 2016 SP1'), 531 | @('SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM'), 532 | @('SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1'), 533 | @('SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1', 'SQL Server 2014 SP2') 534 | foreach ($Product in $Products) { 535 | $TestCases = @() 536 | $Features = Get-SQLDiagFeature -Product $Product 537 | $Features | Foreach-Object {$TestCases += @{Feature = $_}} 538 | It "Returns the correct results for multiple products parameter $Product with a single feature " -TestCases $TestCases { 539 | param($Feature) 540 | $results = $fixes.Where{$_.Product -in $product -and $_.Feature -in $Feature} 541 | Compare-Object (Get-SQLDiagFix -Product $Product -Feature $Feature) $results | Should BeNullOrEmpty 542 | } 543 | } 544 | $Products = @('SQL Server 2012 SP3', 'SQL Server 2016 SP1'), 545 | @('SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM'), 546 | @('SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1'), 547 | @('SQL Server 2012 SP3', 'SQL Server 2016 SP1', 'SQL Server 2016 RTM', 'SQL Server 2014 SP1', 'SQL Server 2014 SP2') 548 | foreach ($Product in $Products) { 549 | ## Generate 10 TestCases of a random number of Features 550 | $TestCases = @() 551 | $x = 10 552 | While ($x -gt 0) { 553 | ## We are testing multiples so we need at least 2 554 | $Number = Get-Random -Maximum $Features.Count -Minimum 2 555 | $Test = @() 556 | While ($Number -gt 0) { 557 | $Test += Get-Random $Features 558 | $Number -- 559 | } 560 | ## Need unique values 561 | $Test = $test | Select-Object -Unique 562 | $TestCases += @{Feature = $Test} 563 | $X -- 564 | } 565 | It "Returns the correct results for multiple products parameter $Product with a multiple feature " -TestCases $TestCases { 566 | param($Feature) 567 | $Test = (Get-SQLDiagFix -Product $Product -Feature $Feature) 568 | ## Annoyingly if there are no results Compare-Object bombs out even though it is correct 569 | ## This is a risky fix for that 570 | if ($Test) { 571 | $results = $fixes.Where{$_.Product -in $product -and $_.Feature -in $Feature} 572 | Compare-Object $test $results | Should BeNullOrEmpty 573 | } 574 | } 575 | } 576 | It 'Checks the Mock was called for Get-SQLDiagRecommendations' { 577 | $assertMockParams = @{ 578 | 'CommandName' = 'Get-SQLDiagRecommendations' 579 | 'Times' = 852 580 | 'Exactly' = $true 581 | } 582 | Assert-MockCalled @assertMockParams 583 | } 584 | } 585 | } 586 | Describe "Get-SQLDiagSupportedRegions" -Tags Build , Unit, Regions { 587 | 588 | Context "Requirements" { 589 | BeforeAll { 590 | Mock Test-Path {$false} 591 | Mock Write-Warning {"Warning"} 592 | } 593 | It "Should throw a warning if there is no API Key XML File and the APIKey Parameter is not used" { 594 | Get-SQLDiagSupportedRegions -ErrorAction SilentlyContinue | Should Be "Warning" 595 | } 596 | It 'Checks the Mock was called for Test-Path' { 597 | $assertMockParams = @{ 598 | 'CommandName' = 'Test-Path' 599 | 'Times' = 1 600 | 'Exactly' = $true 601 | } 602 | Assert-MockCalled @assertMockParams 603 | } 604 | It 'Checks the Mock was called for Write-Warning' { 605 | $assertMockParams = @{ 606 | 'CommandName' = 'Write-Warning' 607 | 'Times' = 1 608 | 'Exactly' = $true 609 | } 610 | Assert-MockCalled @assertMockParams 611 | } 612 | 613 | } 614 | Context "Input" { 615 | 616 | } 617 | Context "Execution" { 618 | It "Returns a warning if unable to get Machine GUID" { 619 | Mock Get-MachineGUID {} -Verifiable 620 | Mock Write-Warning {"Warning"} -Verifiable 621 | Get-SQLDiagSupportedRegions -APIKey dummykey | Should Be "Warning" 622 | Assert-VerifiableMocks 623 | } 624 | 625 | } 626 | Context "Output" { 627 | 628 | } 629 | } 630 | Describe "Invoke-FilePicker" -Tags Build , Unit, Picker { 631 | 632 | BeforeAll {} 633 | Context "Input" {} 634 | Context "Execution" {} 635 | Context "Output" { 636 | Mock Get-Item { [pscustomobject]@{FullName = 'C:\Blah\SQLDump011.mdmp' 637 | Length = 100000000 638 | }} 639 | Mock New-Object {[pscustomobject]@{FileName = 'Dummy'}} 640 | Mock ShowDialog {} 641 | 642 | It "Returns the File Name and Size" { 643 | (Invoke-FilePicker).FullName | Should Be 'C:\Blah\SQLDump011.mdmp' 644 | (Invoke-FilePicker).Length | Should Be 100000000 645 | } 646 | It 'Checks the Mock was called for New-Object' { 647 | $assertMockParams = @{ 648 | 'CommandName' = 'New-Object' 649 | 'Times' = 2 650 | 'Exactly' = $true 651 | } 652 | Assert-MockCalled @assertMockParams 653 | } 654 | It 'Checks the Mock was called for ShowDialog' { 655 | $assertMockParams = @{ 656 | 'CommandName' = 'ShowDialog' 657 | 'Times' = 2 658 | 'Exactly' = $true 659 | } 660 | Assert-MockCalled @assertMockParams 661 | } 662 | It 'Checks the Mock was called for Get-Item' { 663 | $assertMockParams = @{ 664 | 'CommandName' = 'Get-Item' 665 | 'Times' = 2 666 | 'Exactly' = $true 667 | } 668 | Assert-MockCalled @assertMockParams 669 | } 670 | } 671 | } 672 | Describe "Get-SQLDiagDumpFile" -Tags Build , Unit, DumpFIle { 673 | BeforeAll {} 674 | Context "Input" { 675 | Mock Invoke-FilePicker {} 676 | Mock Get-Item {} 677 | Mock Test-Path {$true} 678 | It "Should accept no parameter" { 679 | {Get-SQLDiagDumpFile} | Should Not Throw 680 | } 681 | It "Should accept a file parameter" { 682 | {Get-SQLDiagDumpFile -file DUmmy } | Should Not Throw 683 | } 684 | It "Assert mocks for Invoke-FilePicker" { 685 | $assertMockParams = @{ 686 | 'CommandName' = 'Invoke-FilePicker' 687 | 'Times' = 1 688 | 'Exactly' = $true 689 | } 690 | Assert-MockCalled @assertMockParams 691 | } 692 | It "Assert mocks for Get-Item" { 693 | $assertMockParams = @{ 694 | 'CommandName' = 'Get-Item' 695 | 'Times' = 1 696 | 'Exactly' = $true 697 | } 698 | Assert-MockCalled @assertMockParams 699 | } 700 | It "Assert mocks for Test-Path" { 701 | $assertMockParams = @{ 702 | 'CommandName' = 'Test-Path' 703 | 'Times' = 1 704 | 'Exactly' = $true 705 | } 706 | Assert-MockCalled @assertMockParams 707 | } 708 | } 709 | Context "Execution" { 710 | It "Should call Invoke-FilePicker if no File paramater" { 711 | Mock Invoke-FilePicker {} 712 | Get-SQLDiagDumpFile | Out-Null 713 | $assertMockParams = @{ 714 | 'CommandName' = 'Invoke-FilePicker' 715 | 'Times' = 1 716 | 'Exactly' = $true 717 | } 718 | Assert-MockCalled @assertMockParams 719 | } 720 | } 721 | Context "Output" { 722 | BeforeAll { 723 | Mock Invoke-FilePicker { [pscustomobject]@{FullName = 'C:\Blah\SQLDump011.mdmp' 724 | Length = 100000000 725 | } 726 | } 727 | Mock Get-Item { [pscustomobject]@{FullName = 'C:\Blah\SQLDump011.mdmp' 728 | Length = 100000000 729 | } 730 | } 731 | Mock Test-Path {$true} 732 | $FileObject = [pscustomobject]@{FullName = 'C:\Blah\SQLDump011.mdmp' 733 | Length = 95.367431640625 734 | } 735 | } 736 | It "Returns File Name and Size without file parameter" { 737 | Compare-Object (Get-SQLDiagDumpFile) $FileObject | Should BeNullOrEmpty 738 | } 739 | It "Returns File Name and Size with a file parameter" { 740 | Compare-Object (Get-SQLDiagDumpFile -file Dummy) $FileObject | Should BeNullOrEmpty 741 | } 742 | It "Assert mocks for Invoke-FilePicker" { 743 | $assertMockParams = @{ 744 | 'CommandName' = 'Invoke-FilePicker' 745 | 'Times' = 1 746 | 'Exactly' = $true 747 | } 748 | Assert-MockCalled @assertMockParams 749 | } 750 | It "Assert mocks for Get-Item" { 751 | $assertMockParams = @{ 752 | 'CommandName' = 'Get-Item' 753 | 'Times' = 1 754 | 'Exactly' = $true 755 | } 756 | Assert-MockCalled @assertMockParams 757 | } 758 | It "Assert mocks for Test-Path" { 759 | $assertMockParams = @{ 760 | 'CommandName' = 'Test-Path' 761 | 'Times' = 1 762 | 'Exactly' = $true 763 | } 764 | Assert-MockCalled @assertMockParams 765 | } 766 | } 767 | } 768 | Describe "Get-SQLDiagAnalysisHistory" -Tags Build , Unit, history { 769 | BeforeAll {} 770 | Context "Requirements" { 771 | BeforeAll { 772 | Mock Test-Path {$false} 773 | Mock Write-Warning {"Warning"} 774 | } 775 | It "Should throw a warning if there is no API Key XML File and the APIKey Parameter is not used" { 776 | Get-SQLDiagAnalysisHistory -ErrorAction SilentlyContinue | Should Be "Warning" 777 | } 778 | It 'Checks the Mock was called for Test-Path' { 779 | $assertMockParams = @{ 780 | 'CommandName' = 'Test-Path' 781 | 'Times' = 1 782 | 'Exactly' = $true 783 | } 784 | Assert-MockCalled @assertMockParams 785 | } 786 | It 'Checks the Mock was called for Write-Warning' { 787 | $assertMockParams = @{ 788 | 'CommandName' = 'Write-Warning' 789 | 'Times' = 1 790 | 'Exactly' = $true 791 | } 792 | Assert-MockCalled @assertMockParams 793 | } 794 | 795 | } 796 | Context "Input" {} 797 | Context "Execution" {} 798 | Context "Output" {} 799 | } 800 | Describe "Template" -Tags Build , Unit, Template { 801 | BeforeAll {} 802 | Context "Input" {} 803 | Context "Execution" {} 804 | Context "Output" {} 805 | } 806 | } 807 | 808 | <# 809 | No idea why this test keeps throwing a warning 810 | 811 | Describe "Invoke-SQLDumpAnalysis" -Tags Build , Unit, Invoke { 812 | BeforeAll {} 813 | Context "Requirements" { 814 | BeforeAll { 815 | Mock Write-Warning {"Warning"} 816 | } 817 | It "Should throw a warning if there is no API Key XML File and the APIKey Parameter is not used" { 818 | Mock Test-Path {$false} -ParameterFilter {$Path -eq "${env:\userprofile}\SQLDiag.Cred"} 819 | Mock Get-SQLDiagSupportedRegions {'West US'} 820 | Invoke-SQLDiagDumpAnalysis -File File -Region 'West US' -email a@a.com -ErrorAction SilentlyContinue | Should Be "Warning" 821 | } 822 | It 'Checks the Mock was called for Test-Path' { 823 | $assertMockParams = @{ 824 | 'CommandName' = 'Test-Path' 825 | 'Times' = 1 826 | 'Exactly' = $true 827 | } 828 | Assert-MockCalled @assertMockParams 829 | } 830 | It 'Checks the Mock was called for Get-SQLDiagSupportedRegions' { 831 | $assertMockParams = @{ 832 | 'CommandName' = 'Get-SQLDiagSupportedRegions' 833 | 'Times' = 1 834 | 'Exactly' = $true 835 | } 836 | Assert-MockCalled @assertMockParams 837 | } 838 | It 'Checks the Mock was called for Write-Warning' { 839 | $assertMockParams = @{ 840 | 'CommandName' = 'Write-Warning' 841 | 'Times' = 1 842 | 'Exactly' = $true 843 | } 844 | Assert-MockCalled @assertMockParams 845 | } 846 | 847 | } 848 | Context "Input" { 849 | BeforeAll{ 850 | Mock Test-Path {$true} 851 | Mock Get-SQLDiagSupportedRegions {'West US'} 852 | } 853 | It "Should get file information if file path as string passed as parameter" { 854 | Mock Get-Item {New-Object System.IO.FileInfo ('File') } 855 | Mock Invoke-WebRequest {'Something to fill $response'} 856 | Mock Get-UploadURL {} -ModuleName SQLDIagAPI 857 | Mock Start-FileUpload {$true} -ModuleName SQLDIagAPI 858 | Mock Start-FileAnalysis {} -ModuleName SQLDIagAPI 859 | Mock Get-MachineGUID {} -ModuleName SQLDIagAPI 860 | Mock Import-Clixml { 861 | $secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force 862 | New-Object System.Management.Automation.PSCredential ("username", $secpasswd) 863 | } 864 | Invoke-SQLDiagDumpAnalysis -File File -Region 'West US' -email a@a.com -ErrorAction SilentlyContinue 865 | $assertMockParams = @{ 866 | 'CommandName' = 'Get-Item' 867 | 'Times' = 2 868 | 'Exactly' = $true 869 | } 870 | Assert-MockCalled @assertMockParams 871 | } 872 | It 'Checks the Mock was called for Get-UploadURL' { 873 | $assertMockParams = @{ 874 | 'CommandName' = 'Get-UploadURL' 875 | 'Times' = 1 876 | 'Exactly' = $true 877 | } 878 | Assert-MockCalled @assertMockParams 879 | } 880 | It 'Checks the Mock was called for Test-Path' { 881 | $assertMockParams = @{ 882 | 'CommandName' = 'Test-Path' 883 | 'Times' = 2 884 | 'Exactly' = $true 885 | } 886 | Assert-MockCalled @assertMockParams 887 | } 888 | It 'Checks the Mock was called for Get-SQLDiagSupportedRegions' { 889 | $assertMockParams = @{ 890 | 'CommandName' = 'Get-SQLDiagSupportedRegions' 891 | 'Times' = 1 892 | 'Exactly' = $true 893 | } 894 | Assert-MockCalled @assertMockParams 895 | } 896 | It 'Checks the Mock was called for Import-CliXml' { 897 | $assertMockParams = @{ 898 | 'CommandName' = 'Import-Clixml' 899 | 'Times' = 1 900 | 'Exactly' = $true 901 | } 902 | Assert-MockCalled @assertMockParams 903 | } 904 | It 'Checks the Mock was called for Get-MachineGUID' { 905 | $assertMockParams = @{ 906 | 'CommandName' = 'Get-MachineGUID' 907 | 'Times' = 1 908 | 'Exactly' = $true 909 | } 910 | Assert-MockCalled @assertMockParams 911 | } 912 | } 913 | Context "Execution" {} 914 | Context "Output" {} 915 | } 916 | #> -------------------------------------------------------------------------------- /tests/json/Features.Json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLDBAWithABeard/SQLDiagAPI/4dd237276351e3175bd13352063b0c5444ba4b3b/tests/json/Features.Json -------------------------------------------------------------------------------- /tests/json/Fix.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLDBAWithABeard/SQLDiagAPI/4dd237276351e3175bd13352063b0c5444ba4b3b/tests/json/Fix.json -------------------------------------------------------------------------------- /tests/json/LatestCuProductDefault.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLDBAWithABeard/SQLDiagAPI/4dd237276351e3175bd13352063b0c5444ba4b3b/tests/json/LatestCuProductDefault.json -------------------------------------------------------------------------------- /tests/json/ProductFeatures.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLDBAWithABeard/SQLDiagAPI/4dd237276351e3175bd13352063b0c5444ba4b3b/tests/json/ProductFeatures.json -------------------------------------------------------------------------------- /tests/json/recommendations.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SQLDBAWithABeard/SQLDiagAPI/4dd237276351e3175bd13352063b0c5444ba4b3b/tests/json/recommendations.json --------------------------------------------------------------------------------