799
Chapter 30: Confi guring and Managing SQL Server with PowerShell
30
$did = $DepartmentID
}
$r = """" + $DepartmentID + """,""" + $Name + ""","""
$r = $r + $FirstName + """,""" + $LastName + ""","""
$r = $r + $JobTitle + """,""" + $BirthDate + """,""" + $SalariedFlag +
""""
$f = $Name + ".txt"
$r | out-file $f -append -encoding ASCII
}
$dr.Close()
$cn.Close()
Summary
After looking at the basics of PowerShell and exploring a few ways to get some interesting
information about servers, this chapter reviewed a script to provide information about each
server you manage. Then it examined some of the structures in SQL Server Management
Objects (SMO) and some scripts to perform basic administrative tasks. This chapter also
looked at a couple scripts to extract data from SQL Server because that’s a common request
from business people. Finally, this chapter took a quick look at the features in SQL Server
2012 to make PowerShell an integral part of the SQL Server toolset.
Much more can be explored with PowerShell, but this provides a starting point. Automation
enables administrators to do more in less time and provide more value to the companies
that employ them. PowerShell is a powerful way to automate almost everything an admin-
istrator needs to do with SQL Server.
c30.indd 799c30.indd 799 7/31/2012 9:46:24 AM7/31/2012 9:46:24 AM
http://www.it-ebooks.info