Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Dirty Dozen: PowerShell Scripts for the Busy DBA DBA-237 Aaron

Similar presentations


Presentation on theme: "The Dirty Dozen: PowerShell Scripts for the Busy DBA DBA-237 Aaron"— Presentation transcript:

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

2 DBA 2378 The Dirty Dozen: PowerShell About Me: I’ve been working with databases for over 10 years I’m, a Second Generation DBA I blog at SQLvariant.comSQLvariant.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 DBA 2378 The Dirty Dozen: PowerShell 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 DBA 2378 The Dirty Dozen: PowerShell 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 DBA 2378 The Dirty Dozen: PowerShell THE Module for SQL Server is SQLPSX http:// SQLPSX.CodePlex. com

6 DBA 2378 The Dirty Dozen: PowerShell How Many of You Like Repetitively Clicking Around SSMS?

7 DBA 2378 The Dirty Dozen: PowerShell How Many People Here Are Already Using PowerShell?

8 DBA 2378 The Dirty Dozen: PowerShell How Many People Here Are Developers?

9 DBA 2378 The Dirty Dozen: PowerShell Please Fill Out the Survey Form!!

10 DBA 2378 The Dirty Dozen: PowerShell What’s this Methods & Properties Business? Methods are just verbs : Like Drop Table Properties are adjectives: Like Auto- Shrink Enabled NEVER DO THIS

11 DBA 2378 The Dirty Dozen: PowerShell Deciphering PowerShell $SomeTable is 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 DBA 2378 The Dirty Dozen: PowerShell Variables in PowerShell Get “Expanded” DECLARE @DataBaseNameVARCHAR(128) = 'ReportServer', @SQLVARCHAR(2000) SET @SQL = 'SELECT * FROM '+@DataBaseName+'.INFORMATION_SCHEMA.COLUMNS' $DataBaseName="ReportServer" invoke-sqlcmd -query "SELECT * FROM $DataBaseName.INFORMATION_SCHEMA.COLUMNS" ` -ServerInstance D2 -database master

13 DBA 2378 The Dirty Dozen: PowerShell Deciphering PowerShell This is a.Net thingie [System.Reflection.Assembly]::LoadWithPartial Name("Microsoft.SqlServer.Smo") This is another a.Net thingie [Microsoft.SqlServer.Management.Smo.Smo Application]::EnumAvailableSqlServers()

14 DBA 2378 The Dirty Dozen: PowerShell 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 DBA 2378 The Dirty Dozen: PowerShell If you need help please reach out on twitter and use the #PoShHelp hashtag Also, the #PowerShell tag is great for finding out news about PowerShell. It is VERY widely followed.

16 DBA 2378 The Dirty Dozen: PowerShell If you want to see more slides you better leave now because it’s all scripts from here

17 DBA 2378 The Dirty Dozen: PowerShell 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


Download ppt "The Dirty Dozen: PowerShell Scripts for the Busy DBA DBA-237 Aaron"

Similar presentations


Ads by Google