+ All Categories
Home > Technology > SQL 2012 and Powershell for the Bleeding Edge DBA

SQL 2012 and Powershell for the Bleeding Edge DBA

Date post: 15-Jan-2015
Category:
Upload: dpcobb
View: 2,564 times
Download: 0 times
Share this document with a friend
Description:
Overview of Powershell 3 tools and features and SQL 2012 Cmdlets and SMO. From recent presentation for SFSSUG.com
Popular Tags:
23
SQL 2012 and PowerShell for the bleeding edge SQL Developer David Cobb MCTIP SQL 2008 MCT [email protected] http://daveslog.com
Transcript
Page 1: SQL 2012 and Powershell for the Bleeding Edge DBA

SQL 2012 and PowerShell for the bleeding edge SQL DeveloperDavid CobbMCTIP SQL 2008MCT

[email protected]://daveslog.com

Page 2: SQL 2012 and Powershell for the Bleeding Edge DBA

About Dave

0 Computer consultant since 19960 Background in technical support, web application design, network

administration0 Primarily Windows, SQL Server0 Dabble in Linux, Opensource

0 Microsoft Certified SQL Trainer since 2002 0 MCITP, MCAD, MCSE 2000(I like taking tests.) 0 Lead I.T. Engineer with CheckAlt Payment Solutions providing Check21

Remote Deposit Capture solutions.0 Enjoy helping my clients solve their I.T. problems0 PowerShell Student and Fan 0 http://daveslog.com0 [email protected] I like emails.(..when they’re from people)

Page 3: SQL 2012 and Powershell for the Bleeding Edge DBA

Who’s my audience?

0SQL Pros!0 Using SQL 2012, at least in dev0 No PowerShell experience OK0 Some PowerShell or batch programming background.0 Advanced users should learn something too0 Bleeding edge: Eager to learn the latest tools, search

for the answers, and share what you know.

Page 4: SQL 2012 and Powershell for the Bleeding Edge DBA

Overview

0PowerShell 3 Quick Overview0 PowerShell basics0 New PowerShell 3 features0 PowerShell 3 Integrated Scripting Environment (ISE)

0SQL 2012 0 PowerShell Cmdlets0 SMO / SQL Management Objects

0Resources0 Script Explorer0 PowerShell Community Resources

Page 5: SQL 2012 and Powershell for the Bleeding Edge DBA

What’s PowerShell?

0PowerShell is a scripting environment built on .NET which provides one interface to Windows technologies like WMI and COM. 

0Cmd.exe on steroids!0Windows management tool of the future and today 0 It doesn’t replace TSQL, SSIS, .Net or command line,

but it works with all of them. Another tool in your toolbox.

Page 6: SQL 2012 and Powershell for the Bleeding Edge DBA

PowerShell 10103 commands you need to know *

0 Get-Help0 Get-Command0 Get-ChildItem

03 concepts you need to know *0 Cmdlets (Verb-Noun)0 Variables ($myvariable)0 Piping (Get-ChildItem | Where Name -Like "*.txt“)

0Everything else is on the web

*I’m vastly oversimplifying for the purposes of this slide. Learning PowerShell is a journey, not a destination.

Page 7: SQL 2012 and Powershell for the Bleeding Edge DBA

Windows Management Framework 3.0aka PowerShell 3

0 Out of RC Sep 4, 2012http://tinyurl.com/windowsmanagementframework3

0 Built in to Windows 8 and Server 20120 Tons of Cmdlets http://tinyurl.com/powershell3

0 PowerShell Core0 SQL, Sharepoint, SystemCenter, Azure, Hyper-V, Exchange, Lync,

many others0 Every Microsoft product will be managed with PowerShell!

0 Can install to Server 2008 R2 SP1 and 2008 SP2 to manage downlevel servers from Server 20120 Needs Framework 4.00 http://blogs.technet.com/b/servermanager/archive/tags/downle

vel+servers/

Page 8: SQL 2012 and Powershell for the Bleeding Edge DBA

PowerShell changes from 2 to 3

0Mostly backward compatible, use the same scripts.0Use $PSVersionTable to see current version0 If your V2 scripts break, can still run in V2

0 PowerShell.exe –version 20 Invoke-V2Script

Page 9: SQL 2012 and Powershell for the Bleeding Edge DBA

Cool PowerShell 3 Features

0 Module Auto-Loading0 PowerShell Web Access0 Window Remote Management / WinRM Improvements

0 PSEXEC for PowerShell, Like Screen in Unix0 Enable-PSRemoting -SkipNetworkProfileCheck

0 Syntax Improvements0 Where-Object0 $PSDefaultParameterValues0 Hash tables as objects

0 Update-Help0 PowerShell 3 What’s New Page

http://tinyurl.com/ps3whatsnew

Page 10: SQL 2012 and Powershell for the Bleeding Edge DBA

PowerShell 3 Tools

0 From Microsoft0 Integrated Scripting Environment (ISE) for PowerShell 30 Microsoft Script Explorer for Windows PowerShell

0 Community Resources0 PowerShell Community Resources

http://tinyurl.com/pscommunities0 PowerGUI.org

0 PowerShell Tool Vendors0 Sapien0 Idera 0 -???

Page 11: SQL 2012 and Powershell for the Bleeding Edge DBA

PowerShell ISE

0 Integrated Scripting Environment0The IDE for PowerShell0New features in 3.0

0 Intellisense0 Zoom0 Command Add-On

Page 12: SQL 2012 and Powershell for the Bleeding Edge DBA

SQL 2012 PowerShell Extensions0Microsoft® Windows PowerShell Extensions for

Microsoft® SQL Server® 20120 Part of Microsoft® SQL Server® 2012 Feature Pack0 http://tinyurl.com/sql2012featurepack0 Requires PoSH 2, works with PoSH 3

0Requires SMO0Backward Compatible to SQL 2005

Page 13: SQL 2012 and Powershell for the Bleeding Edge DBA

What about SQLPSX?

0Opensource library of dozens of SQL Cmdlets, before Microsoft provided SQLPS.

0Still much more extensive that SQLPS0Wraps calls to SMO in PowerShell Cmdlets Backward

compatible to SQL 20000Last update March 20110Still very useful for prior SQL versions0Partial PowerShell 3 support

http://sqlpsx.codeplex.com/discussions/393377

Page 14: SQL 2012 and Powershell for the Bleeding Edge DBA

SQL Management Objects

0Access all aspects of SQL Server programmatically

0You’ll use this extensively in your PowerShell scripts

0Developer’s Reference: http://tinyurl.com/smoguide0SQLPS Cmdlets wrap this functionality for basic

functions0SQLPSX takes it a step further

http://www.sqlpsx.com/

Page 15: SQL 2012 and Powershell for the Bleeding Edge DBA

Microsoft Script Explorer for Windows PowerShell

0Find community PowerShell scripts, modules and import them to your environment.0(Release Candidate) Aug 9 2012

http://tinyurl.com/scriptexplorer

Page 16: SQL 2012 and Powershell for the Bleeding Edge DBA

Uses PowerShell Script Repositories

0 Technet Script Centerhttp://gallery.technet.microsoft.com/ScriptCenter/

0 PoshCodehttp://poshcode.org/

0 Extendable0PowerShell Community Resources

http://tinyurl.com/pscommunities

Page 17: SQL 2012 and Powershell for the Bleeding Edge DBA

Demo Topics

0Explore SQLPS Cmdlets0Where-Object Syntax Enhancement0Get SQL Server Instances0Manage SQL Windows Services0Read SQL Error Logs0Query Disk Space on SQL Servers0Use WebClient, sp_Blitz and Export-CSV0Script SQL Tables0RestoreMultipleDBs SQL Job

Page 18: SQL 2012 and Powershell for the Bleeding Edge DBA

Resources

0Whatever it is you’re doing with PowerShell, someone has probably done it before and blogged about it!

0Take advantage of the excellent free resources out there for learning PowerShell.

0Read other people’s code, and adapt for your needs.0Use the tools!

Page 19: SQL 2012 and Powershell for the Bleeding Edge DBA

SQL 2012 PowerShell Bloggers

0 Michael Sorens0 http://www.simple-talk.com/sql/database-administration/practical-powershe

ll-for-sql-server-developers-and-dbas-%E2%80%93-part-1/

0 http://www.simple-talk.com/sql/database-administration/practical-powershell-for-sql-server-developers-and-dbas-%E2%80%93-part-2/

0 Donabel Santos0 http://www.sqlmusings.com/0 Check out her webcast for Idera

http://www.idera.com/Education/PowerShell-Webcasts/0 Wrote the book on SQL 2012 and PowerShell

http://www.packtpub.com/sql-server-2012-with-powershell-v3-cookbook/book

0 Laerte Junior0 http://www.simple-talk.com/author/laerte-junior/

Page 20: SQL 2012 and Powershell for the Bleeding Edge DBA

Cool Tools for PowerShell

0SPADE – SQL installation and configurationhttp://sqlspade.codeplex.com/

0PowerShell WMI Explorerhttp://www.powershellpro.com/wmi-explorer/160/

0PowerShell Scriptomatichttp://tinyurl.com/scriptomaticv2

0PowerGUI – Wrap your scripts in a GUIhttp://www.sapien.com/software/powershell_studio

Page 21: SQL 2012 and Powershell for the Bleeding Edge DBA

PowerShell Help

0Stackoverflow.comhttp://stackoverflow.com/questions/tagged/PowerShell

0PowerShell Community Resourceshttp://tinyurl.com/pscommunities

0 Just search the web many great bloggers, may great resources

Page 22: SQL 2012 and Powershell for the Bleeding Edge DBA

Call to Action

0Learn PowerShell 3!0 Tons of free resources on the web0 Play and learn

0Use SQL 2012 with PowerShell Cmdlets from the feature pack

0Explore scripts available on the web0 You’re probably not the first one with that problem, find

their solution and adapt it for your environment.0Share what you learn

Page 23: SQL 2012 and Powershell for the Bleeding Edge DBA

References

0 Dr Tobias Weltner’s Mastering PowerShellhttp://PowerShell.com/Mastering-PowerShell.pdf

0 PowerShell V2 Owners Manualhttp://tinyurl.com/ps2ownersmanual

0 Windows PowerShell 3.0 and Server Manager Quick Reference Guideshttp://tinyurl.com/ps3quickref

0 Stairway to SQL PowerShellhttp://www.sqlservercentral.com/stairway/91327/

0 Running PowerShell 2 and 3 side by sidehttp://mcpmag.com/articles/2011/12/20/powershell-2-and-3-side-by-side.aspx


Recommended