Advanced PowerShell Scripting Jeffrey P. Snover Partner Architect.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Preface Demo A Quick Thank You How Did We Do It?
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
demo Default WANGPSLookup Default WANGPS.
Co- location Mass Market Managed Hosting ISV Hosting.
 Jeffrey Snover Partner Architect Microsoft Corporation.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
var site="s15gizmodo" var site="s15gizmodo"
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Announcing Demo Announcing.
Feature: OLE Notes Migration Utility
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
 Rico Mariani Architect Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Print Remaining Documents © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Connect with life Connect with life
NEXT: Overview – Sharing skills & code.
FonePlus Hugh Teegan Architect Mobile Devices Microsoft Corporation.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Suggested Item Enhancements – Sales Script and Additional Information © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
 Paul Vick Principal Architect Microsoft Corporation  Lucian Wischik Software Engineer Microsoft Corporation.
Feature: Employee Self Service Timecard Entry © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
announcing Dev Manager Do I understand what we’ve built? Developer Can I bet on using this shared component? Testers What’s changed since I last.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

INF204 - What's New in Windows PowerShell V2 Jeffrey P. Snover Partner Architect.
MIX 09 4/17/2018 4:41 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
9/11/2018 5:53 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Возможности Excel 2010, о которых следует знать
Title of Presentation 11/22/2018 3:34 PM
Title of Presentation 12/2/2018 3:48 PM
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
The Dirty Dozen: Windows PowerShell Scripts for the Busy DBA
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
Silverlight Debugging
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
PENSACOLA ENERGY WORK PLAN OCTOBER 10, 2016
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
Title of Presentation 7/24/2019 8:53 PM
TechEd /30/2019 7:18 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Presentation transcript:

Advanced PowerShell Scripting Jeffrey P. Snover Partner Architect

Agenda State of the Software Community Technology Preview Forms and Styles of Scripting V1 Advanced Scripting Techniques Scriptblocks Switch V2 Advanced Scripting Techniques Cmdlets PSJobs Warning: this will do DEEP and FAST quickly

State of the Software Phenomenal rate of adoption > 1.55 Million downloads in < 1 year Exchange 2007, MOM 2007, Virtual Machine Manager 2007, Lotus Domino Transporter Suite, Data Protection Manager, Compute Cluster Tool Pack, Windows Server, Backup Good ISV pickup > 20 new internal partners CEC 2009 requirement Won both Best of TechEd and Teched Attendees Pick

State of the Software - Community Active and useful Newsgroups and Forums 25 Codeplex projects (2 in the top 25 most active) Strong group of MVPs Strong community tools

Tower of Power

Announcing : PowerShell V2 Community Technology Preview (CTP)

Availability /Applicability The PowerShell V2 CTP is not for everyone Read this PowerShell Team blog entry: watch-this-space.aspxhttp://blogs.msdn.com/powershell/archive/2007/11/02/ctp- watch-this-space.aspx

PowerShell V2 Themes Universal Code Execution Model GUI over PowerShell Production Scripting Community Feedback

Call To Action Read the PowerShell blog Download PowerShell CTP On non-production systems Kick the tires and let us know what we got right/wrong Let us know about any incompatibilities with V1

Scripts Filters Functions Cmdlets [New in V2]

Ad Hoc Run at the command line Simple BASH style Parameters are not named or typed Formal Parameters are named, typed, have initializers Sophisticated Rich error handling Support –Verbose, -Debug, -Confirm, -Whatif Digitally signed

Styles of Scripting Jeffrey Snover Windows Management Partner Architect

Script Blocks Script is a first class datatype Already used in lots of the utilities and infrastructure ScriptBlocks can have parameters You can pipeline to ScriptBlocks using BEGIN,PROCESS,END code blocks $x={BEGIN{$x=0} PROCESS{$x++; write-verbose “$x $_”}} Get-Process |&$x Scriptblocks can be parameters [ScriptBlock]$AssemblyFilter Scoping depends upon invocation. $x #Runs in current scope & $x #Runs in a new scope Invoke-Command $x # Runs in a new scope

ScriptBlocks Jeffrey Snover Windows Management Partner Architect

Switch Queen of Control statements Combines pattern matching, branching and iteration Can operate on a singleton or a collection VERY rich pattern matching Can process an entire file Switch –options ( ){ { } { } default { } }

Switch Jeffrey Snover Windows Management Partner Architect

Script Cmdlets Functions, Filters, Cmdlets Supports most everything a.NET Cmdlet can do Attributes on Cmdlet -SupportsShouldProcess -ConfirmImpact {Low|Medium|High} Attributes on Parameters $CMDLET similar to a C# THIS $Cmdlet.ShouldProcess(“Target”, “Action”) $Cmdlet.ShouldContinue(“Query”, “Caption”) Engine does a TON of work for you Drives consistent syntax and semantics

Parameter Attributes Mandatory Position(int) Alias(string) ValueFromPipeline, ValueFromPipeLineByName AllowNull, AllowEmptyString, AllowEmptyCollection ValidateRange(int,int), ValidateLength(int,int), ValidateNotNull, ValidateNotNullOrEmpty, ValidatePattern(regex), ValidateSet(string[],bool), ValidateCount(int,int), ValidateScript(scriptblock) Customer attributes supported as well ParameterSets are not supported in this CTP

$cmdlet Methods CurrentProviderLocation, GetResolvedProviderPathFromPSPath, GetResourceString, GetUnresolvedProviderPathFromPSPath, GetVariableValue Invoke ShouldContinue, ShouldProcess ThrowTerminatingError, WriteCommandDetail, WriteDebug, WriteError, WriteObject, WriteProgress, WriteVerbose, WriteWarning Properties CommandOrigin, CommandRuntime, Host, InvokeCommand, InvokeProvider, JobRepository, MyInvocation, ParameterSetName, SessionState, Stopping

ScriptCmdlet – Engine Functions -OutVariable -ErrorAction, -ErrorVariable -Whatif, -Confirm, -Verbose -Debug

ScriptCmdlets Jeffrey Snover Windows Management Partner Architect

V2 – Universal Code Execution Model Commands, expressions and ScriptBlocks can be run in the foreground or background on one or more machines over a LAN or a WAN in unrestricted or restricted environments using short or long connections using impersonation or supplied credentials initiated by user input or by events

Universal Code Execution Model ForegroundBackground LocalInvoke-ExpressionStart-Psjob Wait/Receive/Stop Remote / Remote many -ComputerName -Runspace -Throttle -PSCredential -ShellName -ComputerName -Runspace -Throttle -PSCredential -ShellName

Background Jobs Commands, expressions and scriptblocks can be run in the foreground or background on one or more machines PSJOB – Start, Get, Wait, Receive, Stop, Remove Provide a runspace or it will create a local runspace connection Jobs can contain ChildJobs Operate on them individually or collectively

Now available at: Search for PowerShell Try it, Deploy it, Use it, Share

Newsgroup: Microsoft.Public.Windows.PowerShell Team blog: PowerShellCommunity.Org: Channel 9 Wikihttp://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellWiki Script Center: CodePlex: Many excellent books Manning Press book by PowerShell Dev Lead Bruce Payette: PowerShell in Action O’Reilly book by PowerShell Dev Lee Holmes – Windows PowerShell Cookbook

Questions?

Complete your evaluation on the My Event pages of the website at the CommNet or the Feedback Terminals to win!

© 2007 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.