Title of Presentation

Download Report

Transcript Title of Presentation

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
• 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
Tower of Power
Productivity
Mailbox
Statistics
Exchange 2003 (VBScript)
E12 (Monad Script)
Set listExchange_Mailboxs =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\COMPUTERNAME\ROOT\MicrosoftExchangeV2").
InstancesOf("Exchange_Mailbox")
get-mailboxstatistics
–server $servername
For Each objExchange_Mailbox in listExchange_Mailboxs
WScript.echo "AssocContentCount
=” + objExchange_Mailbox.AssocContentCount
WScript.echo " DateDiscoveredAbsentInDS =” + objExchange_Mailbox.DateDiscoveredAbsentInDS
WScript.echo " DeletedMessageSizeExtended =” + objExchange_Mailbox. DeletedMessageSizeExtended
WScript.echo " LastLoggedOnUserAccount =” + objExchange_Mailbox. LastLoggedOnUserAccount
WScript.echo " LastLogoffTime =” + objExchange_Mailbox. LastLogoffTime
WScript.echo " LastLogonTime
=” + objExchange_Mailbox. LastLogonTime
WScript.echo " LegacyDN =” + objExchange_Mailbox. LegacyDN
WScript.echo " MailboxDisplayName =” + objExchange_Mailbox. MailboxDisplayName
WScript.echo " MailboxGUID
=” + objExchange_Mailbox. MailboxGUID
WScript.echo " ServerName
=” + objExchange_Mailbox. ServerName
WScript.echo " Size =” + objExchange_Mailbox. Size
WScript.echo " StorageGroupName
=” + objExchange_Mailbox. StorageGroupName
WScript.echo " StorageLimitInfo
=” + objExchange_Mailbox. StorageLimitInfo
WScript.echo " StoreName
=” + objExchange_Mailbox. StoreName
WScript.echo " TotalItems
=” + objExchange_Mailbox. TotalItems
Next
Database
Mgmt
Dim StorGroup as New CDOEXM.StorageGroup
StorGroup.DataSource.Open "LDAP://" + DCServer + "/ CN=First Storage
Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative Group,
CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services,
CN=Configuration," + DomainName
StorGroup.MoveLogFiles("C:\newlogPath", 0)
Recipient
Mgmt
Dim objMailbox As CDOEXM.IMailboxStore
Set objMailbox = GetObject("LDAP://" + DCServer + "CN=FOO,CN=users," + DomainName)
objMailbox.CreateMailbox "LDAP://" + DCServer + "/CN=Private MDB,CN=First Storage
Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative Group,
CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services,
CN=Configuration," + DomainName
move-storagegrouppath
-identity “First Storage
Group“
–log "C:\newlogPath”
enable-mailbox
-identity domain\FOO
–database “First Storage
Group\Private MDB”
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
Universal Code Execution Model
GUI over PowerShell
Production Scripting
Community Feedback
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
Universal Code
Execution Model
Features
• Remoting
• Mobile Object Model
• Background Jobs
• Restricted Runspaces
• Eventing (coming soon)
Universal Code
Execution Model
Universal Code Execution Model
Foreground
Background
Local
Invoke-Expression
Start-Psjob
Wait/Receive/Stop
Remote / Remote
many
-ComputerName <name[]>
-Runspace <runspace[]>
-Throttle <int>
-PSCredential
-ShellName
<Connection info [port, useSSL,
shellid]>
-ComputerName <name[]>
-Runspace <runspace[]>
-Throttle <int>
-PSCredential
-ShellName
<Connection info [port, useSSL,
shellid]>
Remoting
Scenario
Goal
1:Many “fan-out
TCO reduction through large scale automation
Interactive
Secure Telnet Replacement
Many:1 “fan-in
Automation of Delegated Administration (for
Hosted Services), Interactive Use
GUI over CLI
Fast and simple local/remote GUIs
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
Ristricted Runspaces
• 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
GUI over PowerShell
Hosting APIs
//Early bound API
PowerShell ps = PowerShell.Create("getprocess").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)
Production Scripting
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 [–supportedcommand cmd] {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
Community Feedback
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]
Resources
•
Technical Communities, Webcasts, Blogs, Chats & User
Groups
http://www.microsoft.com/communities/default.mspx
learn
support
•
•
Microsoft Learning and Certification
http://www.microsoft.com/learning/default.mspx
Microsoft Developer Network (MSDN) & TechNet
http://microsoft.com/msdn
http://microsoft.com/technet
connect
subscribe
MSDN Library
Knowledge
Base Forums
MSDN Magazine
•
•
Trial Software and Virtual Labs
http://www.microsoft.com/technet/downloads/trials/defa
ult.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
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.
Backup Slides
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