Best Practices for Script Design A PowerShell.org TechSession.

Slides:



Advertisements
Similar presentations
Get to Know DSC A PowerShell.org TechSession. Remember Find the latest TechSessions at
Advertisements

Prashant Lambat Sr. Manager SQA Engineering Symantec Corporation, Pune Date: 29 th January 2011.
Key Considerations for Report Generation & Customization Richard Wzorek Director, Production IT Confidential © Almac Group 2012.
Stat-JR: eBooks Richard Parker. Quick overview To recap… Stat-JR uses templates to perform specific functions on datasets, e.g.: – 1LevelMod fits 1-level.
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
M.S. Access Module CAS 133 Russ Erdman. M.S. Access Module Assignment Overview Two options for the unit: All students complete Units A, B and C In class.
Module: Definition ● A logical collection of related program entities ● Not necessarily a physical concept, e.g., file, function, class, package ● Often.
Systems Analysis I Data Flow Diagrams
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 16 Slide 1 User interface design.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Test Automation: An Architected Approach Dan Young March 17th, 2005
Lecture 5 Relational Databases and going multiuser.
Wes Preston Agenda  Quick Intro  Overview  Site Details  Notes and Resources  Questions.
MS WINDOWS POWER SHELL CSE 535 Operating Systems.
Copyright ©: SAMSUNG & Samsung Hope for Youth. All rights reserved Tutorials Software: Building apps Suitable for: Advanced.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Chapter 5CSA 217 Design in Construction Chapter 5 1.
Selecting and Combining Tools F. Duveau 02/03/12 F. Duveau 02/03/12 Chapter 14.
Quick and Easy Costumization Enhancement ModulesOn-Site Development SAP B1 Usability Package How to sell SAP Business One with B1UP ”click to continue”..
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
GDT V5 Web Services. GDT V5 Web Services Doug Evans and Detlef Lexut GDT 2008 International User Conference August 10 – 13  Lake Las Vegas, Nevada GDT.
Microsoft ® Official Course Module XA Using Windows PowerShell ®
Team Skill 6: Building the Right System From Use Cases to Implementation (25)
Appendix A Starting Out with Windows PowerShell™ 2.0.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
EGrid Software Packages Overview. EGrid Introduction Egrid Introduction : A description of the main software packages EGrid Inside : A detailed description.
Introduction of Geoprocessing Topic 7a 4/10/2007.
(A radical interpretation) Tomo Lennox Bow Tie computer services Why Agile Works.
Software Architectural Styles Andrew Midwinter, Mark Mullen, Kevin Wong, Matt Jones 1.
SCIRun and SPA integration status Steven G. Parker Ayla Khan Oscar Barney.
Access session recordings via PowerShell.org A TechSession Kickoff: Summit Recap, State of the Org, and More Don Jones President and CEO, PowerShell.org,
Using the Right Method to Collect Information IW233 Amanda Murphy.
Using Commands Unix / Linux Preparation Course May 6, 2012 Serrekunda, The Gambia.
15/06/2006 The Future of Visual DCT EPICS Collaboration 2006 Argonne National Laboratory
Unified scripts ● Currently they are composed of a main shell script and a few auxiliary ones that handle mostly the local differences. ● Local scripts.
2-1 A Federation of Information Systems. 2-2 Information System Applications.
Pipeline Basics Jared Crossley NRAO NRAO. What is a data pipeline?  One or more programs that perform a task with reduced user interaction.  May be.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
540f07cost12oct41 Reviews Postmortem u Surprises? u Use white background on slides u Do not zip files on CD u Team leader should introduce team members.
Classwork: Common Errors Primary keys: don’t forget them! Primary keys: choose the best one! – “Name” and “birthday” are not the best choices. – “Phone.
Writing to Teach - Tutorials Chapter 2. Writing to Teach - Tutorials The purpose of a tutorial is to accommodate information to the needs of the user.
Lecture 7 Conditional Scripting and Importing/Exporting.
Introduction of Geoprocessing Lecture 9 3/24/2008.
Perfecto Mobile Automation
Get to know Access 2007 How does Access 2007 work? Even if you’ve never used Access before, you can be working with your own Access 2007 database in five.
Breaking Up Is Hard To Do From Monolith to Microservices.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
If you joined the training via telephone, please select Telephone and enter your audio pin if you haven’t already. If you joined with a microphone and.
SQL Database Management
Development Environment
Unit Testing.
Recall The Team Skills Analyzing the Problem (with 5 steps)
Coupling and Cohesion 1.
Deploying and Configuring SSIS Packages
Computerized and Manual Systems
How to use the Going Abroad blog
PowerShell Best Practices for SQL DBA’s
Advanced Database Concepts: Reports & Views
Grow Your Script From Simple to Module
Mass Hunting and exploitation with powershell
Applying Use Cases (Chapters 25,26)
Applying Use Cases (Chapters 25,26)
Cohesion and Coupling.
Michael Wall Senior DBA, Great Western Malting
William Stallings Computer Organization and Architecture
WORKSHOP Establish a Communication and Training Plan
Framework Anil
Presentation transcript:

Best Practices for Script Design A PowerShell.org TechSession

Remember Find the latest TechSessions at Advanced registration is required to attend the live events, where you can participate in Q&A Recordings posted to YouTube, usually in 48 hours.

Today We’ll be looking at best practices for designing scripts that best leverage PowerShell’s native patterns and capabilities. Please submit questions to the Q&A panel as we go – I’ll address them as you submit them.

Basic Information Level: Best practices and patterns for using complex technologies Pre-requisites: Solid experience with Windows PowerShell scripting/programming

Scripting Goals Ease testing and debugging Maximize reuse Minimize programming effort Conform to existing shell usage patterns Get the job done!

Tools vs. Controllers TOOLS Do one thing and one thing only Not tied to a specific context Accept input only via parameters; output only via pipeline Cmdlet-style naming Advanced functions contained in a script module CONTROLLERS Coordinate multiple tools to complete a process Tied to a specific process May read data from files, params, databases, etc. May not use cmdlet-style naming Monolithic script with minimal functionality; mostly logic

Tools Create information for use by other tools Get-, Import-, ConvertFrom-, etc. Process information and take action Get-, Set-, New-, Remove-, etc. Put raw data into a particular form Export-, ConvertTo-, Format-, Out-

Poor Function Get-Something { [CmdletBinding()] Param( [string[]]$ComputerName, [string]$FileName ) if ($PSBoundParameters.ContainsKey('Filename')) { $ComputerName = Get-Content $FileName }

Improved Function Get-Something { [CmdletBinding()] Param( [Parameter(ValueFromPipeline)] [string[]]$ComputerName ) } Get-Content computers.txt | Get-Something Get-ADComputer –filter * | Select –Expand Name | Get-Something

Poor... $objects += $object $objects | Format-Table }

Improved... Write-Output $object } Do-Whatever | Format-Table

General Guidelines If information could ever possibly come from more than one source, make dedicated tools to get it, and feed it to other tools via the pipeline or parameters. If a tool does formatting, puts data someplace (e.g., a database), etc., then that is all the tool should do.

General Guidelines If a tool is making any kind of change, then that is all it should do. It should never also worry about where input came from or where output is going. Remember: If a tool makes changes, it should support –confirm and –whatif; those can only affect one operational within the tool, so the tool should only do that one thing.

Possible Red Flags One parameter set accepts information (like a computer name), while another accepts a source for that information (like a filename) Any use of Get-Content Any use of Format-, Export-, Out-, or ConvertTo- in a tool that also does other work

Controllers Do very little work. Instead, they implement a lot of logic to decide what work to do – and call commands (tools) to do that work. Responsible for the entire cycle of input/work/output. Automate a process, produce a report, display a menu, etc. These control one or more tools to do something useful. Tools may not do a completely useful thing by themselves; the controllers make that happen.

Tools vs. Controllers (Redux) New-ADUser Does one thing Doesn't complete an entire process (e.g., for a new employee) Has no idea where new user info is coming from ProvisionEmployee.ps1 Does many things (user account, home dir, add to groups, etc.) Has a specific source for new user info (perhaps an HR database or spreadsheet) Uses New-ADUser internally

Goal: Testing and Debugging Tools can be tested independently, using the same input (via parameters) a controller might use Makes debugging simpler and more contained Controllers do nothing, so it's easier to test their logic – especially if you've properly implemented –whatif in your tools.

Goal: Reusability Because tools aren't tied to a specific context or use case, they're easier to reuse Because controllers contain little to no functionality, they don't need to offer reusability

Goal: Minimize and Conform Tools work consistently with existing shell patterns (e.g., the same as cmdlets, when you do it right) Controllers become the traditional "glue" script that pulls tools together Controllers can be written more quickly because they don't do complex work; they're only coordinating pre- tested, pre-existing tools

Let's See an Example

Let’s Take Some Questions I know you’ve got ‘em… ask away.

Thank You! Find the latest TechSessions at Advanced registration is required to attend the live events, where you can participate in Q&A Recordings posted to YouTube, usually in 48 hours. Ask follow-up questions in the Forums on PowerShell.org.