PowerShell Best Practices for SQL DBA’s

Slides:



Advertisements
Similar presentations
The Web Warrior Guide to Web Design Technologies
Advertisements

Jason Himmelstein, MVP Senior Technical Director,
Automating SQL Buildouts With Hyper-V and SQL Server 2008 R2 Robert L Davis, Sr. DBA, Microsoft Corp.
James Boother Blog: INTRODUCTION TO POWERSHELL.
Great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows.
CONFIGMGR 2012 R2 OSD TIPS AND TRICKS Presenter - Fred
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
System Center 2012 R2 Windows Azure Pack Service Management Automation 101.
Adding a Module The Import-Module cmdlet  Can be used to load any external module into PowerShell.  Uses the following syntax to add the ActiveDirectory.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
© 2012 LogiGear Corporation. All Rights Reserved Robot framework.
Using Visual Basic 6.0 to Create Web-Based Database Applications
An Introduction to Visual Basic
Basic Programming in Ruby Today’s Topics: Introduction last class irb history log Methods Classes (briefly) Using 3 rd Party Libraries rubygems ‘ require.
PowerShell Basics. o PowerShell is a great way to manipulate server and/or workstation components o It’s geared toward system administrators by creating.
Appendix A Starting Out with Windows PowerShell™ 2.0.
Winrunner Usage - Best Practices S.A.Christopher.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based.
December, 21, 2010 Bartek Bielawski Sr IT Site Services Specialist Warsaw, Poland.
Good PowerShell EXPAND YOUR POWERSHELL SKILLZ BY KIERAN JACOBSEN.
Ganga A quick tutorial Asterios Katsifodimos Trainer, University of Cyprus Nicosia, Feb 16, 2009.
Automated Deployment Framework Using TFS and Custom PowerShell cmdlets to create an automated deployment framework.
An Introduction to Designing, Executing and Sharing Workflows with Taverna Katy Wolstencroft myGrid University of Manchester IMPACT/Taverna Hackathon 2011.
POWERSHELL BASICS. BACKGROUND  Powershell is a task automation and scripting language based off the.NET framework  It provides the user full access.
 It is Microsoft's new task-based command- line shell and scripting language designed especially for system administration.  It helps Information Technology.
Windows PowerShell. What is Windows PowerShell? A command-line interface (CLI) A new way of developing Windows and other products to be more manageable.
------TAO, MARKUS Project IT. JavaDoc ‣ JavaDoc is a standard method of commenting source code (interfaces, classes, methods, instances variables). ‣
POWERSHELL ABOVE AND BEYOND: GUIS, WORKFLOWS, AND MORE Dean Corcoran Partner Service Account Manager (Cloud) – MCT – MCITP:EA Microsoft Australia SESSION.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
 Version 1.0[edit]edit  Version 1.0 was released in 2006 for Windows XP SP2/SP3, Windows Server 2003,
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Introduction to SQL Server Automation with Powershell by Chris Sommer.
Ravikanth C.
.NET Application Development in the CygNet ® Ecosystem Mike Borland, Senior Software Development Manager Dan Snyder, Staff Software Engineer.
PowerShell Chattanooga
Start-SPPowerShell – Introduction to PowerShell for SharePoint Admins and Developers Paul BAker.
Version Control Systems
PowerShell Introduction Copyright © 2016 – Curt Hill.
Windows Server 8 beta og Windows PowerShell 3.0
Supporting Windows 8.1 Krystle Portocarrero | Training Experts Inc.
PowerShell 2.0 Remoting Ravikanth C.
Designing For Testability
Automating AD Administration with Windows PowerShell
Version Control Systems
Getting Started with the Data ONTAP PowerShell Toolkit
PowerShell and ConfigMgr – New cmdlets for 1511 and Beyond
Introduction to PowerShell
SharePoint Saturday Omaha April 2016
Making PowerShell Useful
JavaScript Introduction
Microsoft Ignite NZ October 2016 SKYCITY, Auckland.
Making PowerShell Useful
Getting started with Powershell for the DBA
Exploring the Power of EPDM Tasks - Working with and Developing Tasks in EPDM By: Marc Young XLM Solutions
Making PowerShell Useful
Making PowerShell Useful
Cmdlets “Command-lets”
Smart Integration Express
Test and Verify Instances with DBAchecks
Grow Your Script From Simple to Module
Stata Basic Course Lab 2.
Gold Sponsors.
Tech Ed North America /27/ :04 AM Required Slide
Server & Tools Business
PowerShell for ConfigMgr 2012 SP1
Presentation transcript:

PowerShell Best Practices for SQL DBA’s Ed Wilson, MCDBA Microsoft Scripting Guy 1/10/2019

Ed Wilson Microsoft Scripting Guy “Windows PowerShell 2.0 Best Practices” Scripter@Microsoft.Com @ScriptingGuys Mr.Ed.Wilson on Facebook Ed Wilson on Linked In

Objectives and Take-Aways !($local:BestPractice -eq $global:BestPractice) Script Progression TechNet Script Center Twitter @ScriptingGuys FaceBook – Friend Me Mr.Ed.Wilson Scripter@Microsoft.Com

What is Windows PowerShell? Console Interactive commands Query and configure Run jobs Scripting language Automate everything Sharable and reusable Windows PowerShell 2.0 comes in two flavors: the command line version, and the script version. You can think of combining the DOS prompt with VBScript. This is something that is foreign to Windows people, but has been around in other computing environments for a long time. The console gives you the ability to quickly run cmdlets, external executables, and even code in an interactive fashion. In Windows PowerShell 2.0 you can work on the local host, or run commands against remote computers. Windows PowerShell scripts can use the same cmdlets that are used in the PowerShell console, but can also use COM objects, .NET Framework classes, ADSI, ADO, WMI, and even WIN32 API’s. In the Windows PowerShell console, there is a Start-Transcript cmdlet that records your commands and associated output. I have written a Start-Transcript function for the Windows PowerShell ISE. http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/25/create-a-transcript-of-commands-from-the-windows-powershell-ise.aspx

Progression Modules Advanced Functions Functions Quick Script Console Complexity and Development Time Console

Using Console Aliases Positional Arguments Partial parameter completion Variables Profile functions and aliases Include files (dot sourcing) Import-history

Using Windows PowerShell Console Demo Using Windows PowerShell Console

Quick Script Basically collection of Windows PowerShell commands Add variables Error handling Comments Straight line execution of script If use parameters, add some kind of help #Requires –Version 2.0 Quick scripts range in usefullness and complexity from a collection of commands – and therefore help you to remember that cool sequence you were not sure would work – but did, to scripts that use variables, error handling, and comments. If the script accepts arguments, or parameters, make sure you add some kind of help with an example syntax.

Demo DemoScriptCommands.ps1

Functions Use Verb-Noun Include closing #end function Use Param, not ($myparameter) Use type constraint on parameters Supply default values for params Consider partial param completion in names Choose names that do not conflict Create unique alias for function Use Test-Path to check resource Use Join-Path when building path to resource Often that quick script you dashed off, proved to be rather useful. The next stage in the evolution is to migrate the code and put it into a function. This facilitates re-use – either by copy / paste method, or by dot sourcing the function.

Demo Function DemoScriptFunction.ps1

Advanced Function Help tags Avoid Throw unless actually causes error .Synopsis .Example Avoid Throw unless actually causes error Parameter Validation attributes Avoid Out-Host, Out-Default Return Objects Do not make permanent modifications Env Advanced functions in the Windows PowerShell 2.0 beta were called script cmdlets – a name I still like. Because advanced functions can be used to act like cmdlets: integrate with Get-Help, accept pipeline input, implement parameter validation and do some really sophisticated stuff. You can do all this, and leave the function in a script if you wish, or you may want to migrate it to a separate file to facilitate importing (dot sourcing) or begin thinking about creating a module.

Practical Example Evolution of a function … the conversion module demo  First 6 installments of Weekend Scripter on Hey Scripting Guy blog.

TechNet Script Center Hey Scripting Guy Blog – 99% PowerShell for last 24 months Hey Scripting Guy is 7 days a week! Script Repository – Over 5,000 scripts –some cool, others rather rudimentary. Official Scripting Guys Forum – sweet! TechNet Library content – good stuff Downloads page = nice Coming = more videos, etc.

Social media www.ScriptingGuys.Com http://bit.ly/hsgblog Twitter @ScriptingGuys Scripting Guys group on Facebook Scripting Guys fan page on Facebook Mr.Ed.Wilson on Facebook Ed Wilson on Linked In