420 likes | 585 Views
INF204 - What's New in Windows PowerShell V2. Jeffrey P. Snover Partner Architect. State of the Software – The Good. Phenomenal rate of adoption > 1.55 Million downloads in < 1 year
E N D
INF204 - What's New in Windows PowerShell V2 Jeffrey P. SnoverPartner Architect
State of the Software – The Good • 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 • Solid Community • Active and useful Newsgroups and Forums • 25 Codeplex projects (2 in the top 25 most active) • Strong group of MVPs • 14+ books • Strong tools
State of the Software – Opportunities for Improvement • Cmdlet specific remoting • Can’t write Cmdlets in PowerShell • Script development via Notepad and PS-DEBUG • APIs did not address common GUI over CLI issues
Announcing : PowerShell V2 Community Technology Preview (CTP)
Availability /Applicability • CTP downloadable NOW • CTP is NOT Beta • Full regression tests against V1.0 functions • Good coverage against new functions • Catch-as-catch-can documentation • Things WILL change • Works on XP SP2 and Above • Must download WS-Management V1.1 first • On VISTA – SP1 is required (for remoting) • Replaces V1.0 • V1 compatible except for additions • New variable names • New Language/cmdlet features
PowerShell V2 Themes • 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
Features • Remoting • Mobile Object Model • Background Jobs • Restricted Runspaces • Eventing (coming soon)
Mobile Objects Model • Islands of optimization in a sea of interoperability • Whenever possible, use live.NET objects • Use typed property bags everywhere else • Live objects get serialized at runspace borders • Typed property bags using 22 core datatypes • Everything else is converted using ToString() • Process can be tweaked with typeXML entries • Automatically deserialized into typed property bags on receipt • Type: Deserializes.OriginalType • PSIPHostEntry added (ComputerName, Aliases, Addresses)
Demo: PowerShell Remoting Jeffrey P. Snover Partner Architect
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
Demo: Background Jobs Jeffrey P. Snover Partner Architect
RistrictedRunspaces • Option for hosting PowerShell to create an environment to run potentially hostile requests safely • Service oriented scenarios • $executionContext.SessionState • LanguageMode • FullLanguage, DataLanguage, NoLanguage • Whitelists for Scripts and Applications • Visibility property on Commands and Variables • New model for creating initial session state
Features • New hosting APIs • Runspace pooling
Hosting APIs //Early bound API PowerShell ps = PowerShell.Create("get-process").AddParameter(“Name”,”*SS”).AddCommand("Sort-Object“); //Typed invocation Collection<Process> col = ps.Invoke<Process>(); //Cmd reuse Collection<Process> col = ps.Invoke<Process>();
Demo: APIs Jeffrey P. Snover Partner Architect
Features • Graphical PowerShell • Script Cmdlets • Script Internationalization/Data Language • Debugging • Packages and modules (coming soon)
Demo: Graphical PowerShell Jeffrey P. Snover Partner Architect
Script Cmdlets • Supports most everything a .NET Cmdlet can do • Attributes on Parameters • Attributes on Cmdlet • $CMDLET similar to a C# THIS • $Cmdlet.ShouldProcess(“Target”, “Action”) • $Cmdlet.ShouldContinue(“Query”, “Caption”) • Engine does a TON of work for you • Fewer lines of code delivers more functions in a more consistent way
Demo: Script Cmdlets Jeffrey P. Snover Partner Architect
Script Internationalization/ Data Language • Data var [–supportedcommandcmd] {scriptblock} • Limited subset of language: • Comparison operators (except –Match) • If, elseif, else • Well defined [safe] ConvertFrom-* cmdlets • Limited variables: $culture, $uiculture, $true, $false, $null • Comments and pipelines • Literals • Strings, hash, xml, etc • Save Cmdlets • ConvertFrom-StringData
Script Internationalization/ Data Language Data msgs { ConvertFrom-StringData @” Usage = “Usage: Get-Process Name <name>” NoSuchProc = “No such Process Found” “@ } Import-LocalizedData –Bind msgs …. Throw $msgs.NoSuchProc
Script Debugging • PSBreakPoint • New, Remove, Get, Enable, Disable • Breakpoints can be set on: • Lines, Line/ColumnNumber • Functions • Variable Read/Write • Cmdlets • Action scriptblocks • Step • Into, Over, Out • Get-PsCallStack
Features • Language enhancements • Improved adapters • New/improved cmdlets
Language Enhancements • Splatting operator • $a=@{id=13,23,33; ErrorAction="continue"; ErrorVariable="e"} • stop-process @a • -Split • $x = “1,2,3,4” • $x –split “,” • -Join • $x=“1”,”2”,”3”,”4” • $x –join “,” • [ADSISearcher] • [x[]] • [string[]]”a”,”b”,”c”
Improved Adapters /ADSI support • Improved adapter lookup algorithm • Includes PSBASE to lookup path • Improved ADSI Adapter • Path, Children, Parent, SchemaClassName, SchemaEntry are now available on the object • [ADSISearcher] • DirectoryEntry type has marshalling code methods • ConvertDNBinaryToString • ConvertLargeIntegerToInt64
WMI Improvements • Cmdlets • Get-WmiObject, Remove-WmiObject • Set-WMIInstance • Invoke-WmiMethod • New parameters • -Impersonation, -Authentication, -Locale, -EnableAllPrivileges, -Amended, -DirectRead, -Authority • Connection settings stay with the object [bug fix]
Required slide: Please customize this slide with the resources relevant to your session Resources • Technical Communities, Webcasts, Blogs, Chats & User Groupshttp://www.microsoft.com/communities/default.mspx • Microsoft Learning and Certificationhttp://www.microsoft.com/learning/default.mspx • Microsoft Developer Network (MSDN) & TechNet http://microsoft.com/msdnhttp://microsoft.com/technet • Trial Software and Virtual Labshttp://www.microsoft.com/technet/downloads/trials/default.mspx • New, as a pilot for 2007, the Breakout sessions will be available post event, in the TechEd Video Library, via the My Event page of the website learn support connect subscribe MSDN Library Knowledge Base Forums MSDN Magazine User Groups Newsgroups E-learning Product Evaluations Videos Webcasts V-labs Blogs MVPs Certification Chats Visit MSDN in the ATE Pavilion and get a FREE 180-day trial of MS Visual Studio Team System!
Complete your evaluation on the My Event pages of the website at the CommNet or the Feedback Terminals to win! All attendees who submit a session feedback form within 12 hours after the session ends will have the chance to win the very latest HTC 'Touch' smartphone complete with Windows Mobile® 6 Professional
© 2007 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.
Parser API • [System.Management.Automation.PSParser]::Tokenize • $psp = [System.Management.Automation.PSParser] • $psp::Tokenize(((cat $file) -join "`n"),[ref]$null) | where {$_.type –eq “Command” } | Group Content |sort Name
Graphical PowerShell • VERY early release (lots of known issues) • Requires .NET 3.0 • Supports • Unicode output • Multiline input • Syntax coloring • Script editing • Multiple sessions
Common Remoting Goals • Universal, free, and non-optional for all PowerShell functions/cmdlets/providers • Secure • Firewall Friendly • Protocol/Payload efficient • Streaming behaviour
WS-MGMT • Remoting layers on top of WS-MGMT protocol • WINRM service • Uses HTTP over a fixed (configurable) port • Admin control over resource usage • Max shells per user • Concurrent users • $pshome\Configure-WSMAN.ps1
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