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

To PowerShell or not to PowerShell


The great debate is—why would you use PowerShell to send queries to SQL Server? This is a valid question. What is important to understand is that PowerShell is yet another tool that can help you perform certain tasks. However, by no means is PowerShell the only tool, nor is PowerShell the best tool for all cases.

As a rule of thumb, it is best to use native, set-based T-SQL statements when possible. When you use SMO or ADO.NET, be aware that you are adding one more layer of translation before the query gets to SQL Server, which may not always be efficient.

Running the T-SQL scripts from PowerShell could be useful, especially when it is part of a bigger PowerShell scripting solution. For example, it is useful if you are integrating this into an automation solution between SharePoint, Active Directory, Exchange, and SQL Server, like a script that automatically builds a SharePoint farm. Let's look at a few more cases.

Creating databases and tables would be simpler...