In this chapter, we will look at how to accomplish typical SQL Server administration tasks by using PowerShell. Although you were introduced to SQL Server-specific cmdlets in the previous chapters, these cmdlets are still quite few. Many of the tasks that we will see can be accomplished by using SQL Server Management Objects (SMO). As we encounter new SMO classes, it is best to verify the properties and methods of that class using Get-Help
, or by directly visiting the TechNet or MSDN website.
The topics covered in this chapter include how to perform the following tasks:
Listing databases and tables
Adding files and filegroups
Scripting database objects
Attaching and detaching databases
Backing up and restoring databases
Reorganizing or rebuilding indexes
Managing logins, users, and permissions
Listing policies
Managing jobs