Summary

Many SQL Server administration tasks can be accomplished using PowerShell. In this chapter, we covered tasks ranging from listing databases and files, attaching and detaching databases, monitoring and managing logins and users, to checking jobs and invoking policies.

The SQLPS module comes with some cmdlets that can be used, for example Backup-SqlDatabase and Restore-SqlDatabase, as well as a number of cmdlets related to AlwaysOn. However, the number of cmdlets in SQLPS is still quite few. Often, accomplishing tasks more effectively via scripting will require you to use SMO, especially for tasks where appropriate cmdlets are not available.

In the next chapter, we will explore different ways to send queries to SQL Server via PowerShell.

Get PowerShell for SQL Server Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.