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

Changing configurations


PowerShell can help not only audit your current instance configurations, but can also help if you need to manage and change configurations, such as changing service accounts and default backup folders and turning on (or off) some instance- and database-level features.

Start or stop services

There are a handful cmdlets that work with services. To get these cmdlets, you can use the following command:

Get-Command -Name "*Service*" -CommandType "Cmdlet"

The result you will get is similar to the following screenshot:

To start or stop services, you can use the Start-Service and Stop-Service cmdlets. The following snippet is an example of how you can use these cmdlets. In the following example, we are targeting the SQL Server Agent service of a named instance called SQL2014. This service can be referred to as SQLAgent$SQL2014. Since the $ sign is a special character in PowerShell that signifies variable names, the $ sign in the service name needs to be escaped with a backtick...