270 likes | 949 Views
Required Slide. SESSION CODE: WSV401. Advanced Automation Using Windows PowerShell 2.0. Mir Rosenberg & Refaat Issa Program Managers Microsoft Corporation. Objectives and Takeaways. Demonstrate the advanced features of Windows PowerShell scripting for automating your IT environment
E N D
Required Slide SESSION CODE: WSV401 Advanced Automation Using Windows PowerShell 2.0 Mir Rosenberg & Refaat Issa Program Managers Microsoft Corporation
Objectives and Takeaways • Demonstrate the advanced features of Windows PowerShell scripting for automating your IT environment • Key Takeaways – How To: • Write functions and advanced functions • Make your scripts world-ready • Easily create graphical applications over PowerShell • Incorporate exception handling • Use the Debugger to debug your script or function • Package your functions into modules
FUNCTIONS • Reusable and discoverable • Support for parameters: • Parameter list • Param statement • $args • Parameter initialization • Support for pipeline processing through code blocks: • Begin • Process • End • Missing: Help, parameter sets, validation …
Functions Refaat IssaProgram ManagerMicrosoft Corporation DEMO
ADVANCED FUNCTIONSScriptCmdlets • Cmdlet behavior • Parameter binding • Parameter sets and default parameter set • Support for parameter attributes: metadata & validation • Support for ubiquitous parameters • –whatif • –confirm • –verbose • –debug • Inline and external help
Advanced Functions Refaat IssaProgram ManagerMicrosoft Corporation DEMO
Script Internationalization • Let’s take over the world! • Localize your scripts into any language supported by Windows • Scripts .ps1 files • Resources .psd1 files • If Windows can display it, you can use it! • Cmdlets • Import-LocalizedData • ConvertFrom-StringData
Script Internationalization Mir RosenbergProgram ManagerMicrosoft Corporation DEMO
GUI Over PowerShell • Best practice: Build GUI over PowerShell cmdlets • Easy to build • Easy to change • GUI -le CLI • Choose your own GUI adventure! • Lower the barrier to entry: more users can run automated management tasks
GUI Over PowerShell Mir RosenbergProgram ManagerMicrosoft Corporation DEMO
Debugging • Command-line debugger • Graphical debugger • Set breakpoints: • Line • Variable • Command • Step over, in, out – or specify an action • Hover over variables to see their value, or use the command-line
Debugging Refaat IssaProgram ManagerMicrosoft Corporation DEMO
Exception Handling • V1 had trap • V2 introduced: try{}catch{}finally{} • Put code that can throw an exception in a try block • Have zero or more catch blocks • From most specific to most general exceptions • Put must-execute cleanup code in a finally block
Exception Handling Refaat IssaProgram ManagerMicrosoft Corporation DEMO
Modules • Replace snap-ins • Exceptions: v1 support needed • Enable users to organize PowerShell code into reusable, self-contained units • Provide an isolated execution environment • Ability to repackage and abstract other modules to create custom solutions • Attach metadata to describe module functionality and control loading behavior
Modules Mir RosenbergProgram ManagerMicrosoft Corporation DEMO
Windows PowerShell Community Resources • Team blog: http://blogs.msdn.com/PowerShell • PowerShell Community: http://www.powershellcommunity.org • Newsgroup: Microsoft.Public.Windows.PowerShell • PowerShell Forum: http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/threads • Channel 9: http://channel9.msdn.com/tags/PowerShell • Wiki: http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellWiki • Script Center: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx • CodePlex: http://codeplex.com/Project/ProjectDirectory.aspx?TagName=powershell • Some good books • PowerShell in Action by Bruce Payette http://manning.com/powershell • Windows PowerShell Cookbook by Lee Holmes http://www.oreilly.com/catalog/9780596528492/index.html • Professional Windows PowerShell Programming http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470173939.html
PowerShellCommunity.org • www.PoshComm.org • Free, independent, and open community • Dedicated to the enhancement and enrichment of PowerShell • Increase the awareness and usage of PowerShell • Forums • User group support
Required Slide Speakers, please list the Breakout Sessions, Interactive Sessions, Labs and Demo Stations that are related to your session. Related Content • Breakout Sessions • WSV334 - Windows Server 2008 R2: Tips on Automating and Managing the Breadth of Your IT Environment • WSV401- Advanced Automation using Windows PowerShell 2.0 • WCL308 -Inventory Your Network and Clients with Windows PowerShell • DAT311 -Microsoft SQL Server Management: Reduce TCO Using Policy-Based Management and Windows PowerShell • OSP402 - Windows PowerShell Made Less Scary for the Microsoft SharePoint Server 2010 Administrator • SIA306 - Night of the Living Directory: Understanding the Windows Server 2008 R2 Active Directory… • WSV319 - Manage Your Enterprise from a Single Seat: Windows PowerShell Remoting • WCL313 - Paradigm Shift: Microsoft Visual Basic Scripting Edition to Windows PowerShell • Interactive Sessions • WCL06-INT - Using Windows PowerShell for Enterprise Desktop Automation • WSV09-INT - Server Deployment and Maintenance in Windows Server 2008 R2 • Hands-on Labs • WSV18-HOL - Introduction to Windows PowerShell Fundamentals • WSV19-HOL - Advanced Windows PowerShell Scripting • Product Demo Stations • TLC-WSV8-Orange - Windows PowerShell and Server Management
Required Slide Resources Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers • http://microsoft.com/technet • http://microsoft.com/msdn
Required Slide Complete an evaluation on CommNet and enter to win!
Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st http://northamerica.msteched.com/registration You can also register at the North America 2011 kiosk located at registrationJoin us in Atlanta next year
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
PowerShell’s Value Proposition • Automation is a core challenge for our IT Pros. • PowerShell provides a consistent mechanism across management applications to automate administration tasks • Allows experienced admins to automate tasks which can be run by less-experienced admins • Reduces the dependency on developers writing IT solutions less disconnect & less wait
CMDLETS – A quick refresher • Compiled commands • Discoverable • Consistent naming & syntax • Aliases • Ubiquitous parameters: • -whatif, -confirm, -error, -errorAction, -debug • Parameter sets • Rich help • Formatting
ONE-LINERSAutomating the world … one-liner at a time • Cmdlets emit real objects • The pipeline • $_ • ForEach-Object and Where-Object • Interactive, experimental • Useful, often-used one-liners should be turned into functions