180 likes | 314 Views
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.
E N D
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. • Please download the scripts and follow along if you have your laptop with you.
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
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
THE Module for SQL Server is SQLPSX • http://SQLPSX.CodePlex.com
What’s this Methods & Properties Business? • Methods are just verbs: Like Drop Table • Properties are adjectives: Like Auto-Shrink Enabled • NEVER DO THIS
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)
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
Deciphering PowerShell • This is a .Netthingie[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") • This is another a .Netthingie[Microsoft.SqlServer.Management.Smo.SmoApplication]::EnumAvailableSqlServers()
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
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.
If you want to see more slides you better leave now because it’s all scripts from here
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
Thank you for attending this session and the 2010 PASS Summit in Seattle