1 / 18

The Dirty Dozen: PowerShell Scripts for the Busy DBA

The Dirty Dozen: PowerShell Scripts for the Busy DBA. DBA-237. Aaron Nelson, @ SQLvariant. About Me:. I’ve been working with databases for over 10 years I’m, a Second Generation DBA I blog at SQLvariant.com Aaron@SQLvariant.com All of the scripts shown here are available on my blog.

berit
Download Presentation

The Dirty Dozen: PowerShell Scripts for the Busy DBA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Dirty Dozen: PowerShell Scripts for the Busy DBA DBA-237 Aaron Nelson, @SQLvariant

  2. About Me: • I’ve been working with databases for over 10 years • I’m, a Second Generation DBA • I blog at SQLvariant.com • Aaron@SQLvariant.com • All of the scripts shown here are available on my blog. • Please download the scripts and follow along if you have your laptop with you.

  3. Why PowerShell? • “It’s always useful to keep in mind that PowerShell is not “just” a shell or scripting language. • Its primary purpose is to be an automation tool for managing Microsoft Windows.” • – Bruce Payette • Windows PowerShell in Action Second Edition

  4. PowerShell Bolt-Ons or “Expansion Packs” In addition to the out of the box PowerShell features there are some ‘expansion packs’ in the form of • Snap-Ins and • Modules The Snap-Ins for SQL Server come with SSMS 2008+ and they are • SqlServerCmdletSnapin100 • SqlServerProviderSnapin100

  5. THE Module for SQL Server is SQLPSX • http://SQLPSX.CodePlex.com

  6. How Many of You Like Repetitively Clicking Around SSMS?

  7. How Many People Here Are Already Using PowerShell?

  8. How Many People Here Are Developers?

  9. Please Fill Out the Survey Form!!

  10. What’s this Methods & Properties Business? • Methods are just verbs: Like Drop Table • Properties are adjectives: Like Auto-Shrink Enabled • NEVER DO THIS

  11. Deciphering PowerShell • $SomeTableis a variable • Drop-Database (Verb-Noun) is how cmdlets (and most functions) are named • SQLSERVER:\sql\D2\R2\DATABASES\ Provider Path • $SomeTable.Script() This is a Method being used on an object (in this case the object is a variable)

  12. Variables in PowerShell Get “Expanded” • DECLARE@DataBaseNameVARCHAR(128)='ReportServer',@SQL VARCHAR(2000) • SET@SQL ='SELECT *FROM '+@DataBaseName+'.INFORMATION_SCHEMA.COLUMNS' • $DataBaseName="ReportServer" • invoke-sqlcmd-query"SELECT * FROM $DataBaseName.INFORMATION_SCHEMA.COLUMNS"` • -ServerInstanceD2-databasemaster

  13. Deciphering PowerShell • This is a .Netthingie[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") • This is another a .Netthingie[Microsoft.SqlServer.Management.Smo.SmoApplication]::EnumAvailableSqlServers()

  14. Deciphering PowerShell • So tell me about yourself: • Get-Help is how you find out more about a cmdlet or a function (that has help available) • Get-Member is not just a bad Austin Powers joke the Dev team left laying around. • It’s how you find out all of the Methods and Properties of an object

  15. If you need help please reach out on twitter and use the #PoShHelphashtag • Also, the #PowerShell tag is great for finding out news about PowerShell. It is VERY widely followed.

  16. If you want to see more slides you better leave now because it’s all scripts from here 

  17. Complete the Evaluation Form to Win! • Win a Dell Mini Netbook – every day – just for handing in your completed form. Each session evaluation form represents a chance to win. • Pick up your evaluation form: • In each presentation room • At the PASS Booth near registration • Drop off your completed form: • Near the exit of each presentation room • At the PASS Booth near registration Sponsored by Dell

  18. Thank you for attending this session and the 2010 PASS Summit in Seattle

More Related