Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced PowerShell Scripting Jeffrey P. Snover Partner Architect.

Similar presentations


Presentation on theme: "Advanced PowerShell Scripting Jeffrey P. Snover Partner Architect."— Presentation transcript:

1 Advanced PowerShell Scripting Jeffrey P. Snover Partner Architect

2 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

3 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

4 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

5 Tower of Power

6 Announcing : PowerShell V2 Community Technology Preview (CTP)

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

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

9 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

10 Scripts Filters Functions Cmdlets [New in V2]

11 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

12 Styles of Scripting Jeffrey Snover Windows Management Partner Architect

13 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

14 ScriptBlocks Jeffrey Snover Windows Management Partner Architect

15 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 { } }

16 Switch Jeffrey Snover Windows Management Partner Architect

17 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

18 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

19 $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

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

21 ScriptCmdlets Jeffrey Snover Windows Management Partner Architect

22 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

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

24 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

25 Now available at: www.microsoft.com/downloads www.microsoft.com/downloads Search for PowerShell Try it, Deploy it, Use it, Share

26 Newsgroup: Microsoft.Public.Windows.PowerShell Team blog: http://blogs.msdn.com/PowerShell/ PowerShellCommunity.Org:http://www.PowershellCommunity.Org Channel 9 http://channel9.msdn.com/tags/PowerShell Wikihttp://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 Many excellent books Manning Press book by PowerShell Dev Lead Bruce Payette: PowerShell in Action http://manning.com/powershell/ O’Reilly book by PowerShell Dev Lee Holmes – Windows PowerShell Cookbook http://www.oreilly.com/catalog/9780596528492/index.html

27 Questions?

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

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


Download ppt "Advanced PowerShell Scripting Jeffrey P. Snover Partner Architect."

Similar presentations


Ads by Google