Chapter 23. PowerShell and the SQL Server provider

 

Ben Miller

This chapter is written for the DBA who needs an efficient way to get information from or manage SQL Servers in their environment with just a few commands by using native PowerShell methods. When you’re looking at the options for managing or getting information from a SQL Server by using PowerShell your choice is driven by a few scenarios. One use case might be to find out how many databases are in the instances you maintain while using the simplest way to reference these instances. Another might be to find out whether a certain object exists in a Software as a Service (SaaS) environment with thousands of databases and multiple servers while upgrading in a phased upgrade methodology. You may want to know which database has the object so you don’t attempt to upgrade that database in the second wave and find that the object exists. When faced with these or other scenarios you can quickly accomplish your goal with part PowerShell methods and part SQL Server provider.

Requirements

Introduction to the SQL Server provider

Using the SQL Server provider

Examples of using the SQL Server provider

Getting a count of databases in an instance

Finding a table in many databases

Summary

About the author