Book Image

PowerShell for SQL Server Essentials

By : Donabel Santos
Book Image

PowerShell for SQL Server Essentials

By: Donabel Santos

Overview of this book

Table of Contents (15 chapters)
PowerShell for SQL Server Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Implementing Reusability with Functions and Modules
Index

Preface

PowerShell is Microsoft's platform for task automation. It comes with both a shell and scripting language, and is now more deeply integrated with Microsoft's suite of products. Microsoft applications such as Windows, Exchange, and SharePoint have increased their PowerShell support, and many tasks can now be done without having to go through the user interface. These automated and streamlined tasks equate to time savings and increased productivity for developers, administrators, and IT professionals.

As a database professional, you can also leverage PowerShell in your work. This book introduces you to PowerShell and taps into how you can use PowerShell in the context of SQL Server.

What this book covers

Chapter 1, Getting Started with PowerShell, introduces you to PowerShell and its importance in server management and automation. This chapter is a good starting point for readers who are new to PowerShell and want to get started with its environment and other components.

Chapter 2, Using PowerShell with SQL Server, dives into using SQL Server-specific PowerShell support in different operating systems and SQL Server versions. You will learn about SQL Server-specific modules, cmdlets, and SQL Management Objects (SMO).

Chapter 3, Profiling and Configuring SQL Server, covers how to quickly profile SQL Server and change SQL Server configurations using PowerShell. You will learn more about Get-WmiObject and the SMO Server object.

Chapter 4, Basic SQL Server Administration, covers the tasks in a DBA's checklist. These tasks include getting space/memory usage, backup/restore, enabling features, jobs, alerts, and so on.

Chapter 5, Querying SQL Server with PowerShell, shows the methods to query SQL Server from within PowerShell, its pros and cons, and how to export results.

Chapter 6, Monitoring and Automating SQL Server, teaches you how to perform SQL Server usage and performance monitoring, logging, alerting, and error checking using PowerShell.

Appendix, Implementing Reusability with Functions and Modules, shows some snippets required to accomplish the task at hand. It covers the basics of creating and deploying functions and modules.

What you need for this book

For the purpose of this book, the requirements are as follows:

  • Windows Server 2012 R2 Standard

  • SQL Server 2014 Developer Edition

The system requirements for Windows PowerShell 4.0 and 3.0 are as follows:

  • The OS needs to be Windows 8.1, Windows Server 2012 R2, Windows 7 with Service Pack 1, Windows Server 2008 R2 with Service Pack 1, or Windows Server 2008 (for PowerShell 3.0 only)

  • Microsoft .NET Framework requirements are 4.5 for PowerShell 4.0 and 4 for PowerShell 3.0

  • WS-Management 3.0

  • Windows Management Instrumentation 3.0

  • Common Language Runtime 4.0

Who this book is for

This book is written for SQL Server administrators and developers who want to leverage PowerShell to work with SQL Server. Some background with scripting will be helpful but not necessary.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The -Leaf option provides the filename part of the full path."

A block of code is set as follows:

$server.EnumProcesses() |
Where-Object IsSystem -eq $false |
Select-Object Spid, Database |
Format-Table -AutoSize

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

$server.EnumProcesses() |
Where-Object IsSystem -eq $false |
Select-Object Spid, Database |
Format-Table -AutoSize

Any command-line input or output is written as follows:

Get-Help Get-ChildItem -Online

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You can click on the CPU or Memory option to sort data according to those metrics."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.