Loading...

Scripting SQL Management Objects in Windows PowerShell

Share Icon

ISBN: 978-0-470-27935-9

January 2008

33 pages

Description
This Wrox Blox shows how to communicate with SQL Server using SQL Management Objects instantiated on-the-fly in Windows PowerShell scripts. Topics include how to create Windows PowerShell scripts that use SQL Management Objects (SMO) to manage and program SQL Server. In addition, you will learn about areas of potential difficulty and see how to avoid them—for example, the use of '$' in instance name, quote nesting rules, connection pooling, and schemata. The explanations in this Wrox Blox are focused on numerous code examples, and show you how to do the following: load SMO; create a server object; get a user’s credentials from the UI into a safestring; connect to SQL Server using SQL Server authentication; connect to SQL Server using Windows authentication; profile a server instance by examining its properties; use WMI to examine and configure a server’s Windows service; use PowerShell cmdlets to start, stop, and restart a service; check for the existence of a database; verify a file path; save data in a csv file; retrieve data from a csv file; create a database; create a schema; create a table; insert data in a table; execute ad hoc T-SQL queries; retrieve information about views; create reports in HTML format; display HTML reports in a browser window; launch a Windows process; and tweak data format. A downloadable ZIP archive is included which contains all the example scripts, as well as additional scripts.

Usage Rights for Wiley Wrox Blox

Any Wrox Blox you purchase from this site will come with certain restrictions that allow Wiley to protect the copyrights of its products. After you purchase and download this title, you:

  • Are entitled to three downloads
  • Are entitled to make a backup copy of the file for your own use
  • Are entitled to print the Wrox Blox for your own use
  • Are entitled to make annotations and comments in the Wrox Blox file for your own use
  • May not lend, sell or give the Wrox Blox to another user
  • May not place the Wrox Blox file on a network or any file sharing service for use by anyone other than yourself or allow anyone other than yourself to access it
  • May not copy the Wrox Blox file other than as allowed above
  • May not copy, redistribute, or modify any portion of the Wrox Blox contents in any way without prior permission from Wiley
  • May not copy the Wrox Blox file other than as allowed above
  • May not copy, redistribute, or modify any portion of the Wrox Blox contents in any way without prior permission from Wiley

If you have any questions about these restrictions, you may contact Customer Care at (877) 762-2974 (8 a.m. - 5 p.m. EST, Monday - Friday). If you have any issues related to Technical Support, please contact us at 800-762-2974 (United States only) or 317-572-3994 (International) 8 a.m. - 8 p.m. EST, Monday - Friday).

About the Author
Willis Johnson is a consultant specializing in data security and privacy. He worked as a programmer–writer in Microsoft’s SQL Server product group for the 5+-year duration of the SQL Server 2005 product cycle, writing sample code, white papers, and documentation for a variety of SQL technologies. He claims to have read (skimmed) the SQL Server 2005 RTM Books Online in its entirety. He has taught classes on data security, networking, distributed file systems, and C# at Microsoft and at the U.C. Berkeley Haas Business School. He has a Ph.D. in Near Eastern Studies from U.C. Berkeley, an M.Phil. in History from Cambridge (UK), and a B.A. in English from Reed College. He lives in Evanston, Illinois. He can be reached at [email protected].
The author also gratefully acknowledges Joe Brinkman for his insightful technical edit of this article.
Series