Nicolas Blank – Zlatan Dzinic Exchange & SharePoint MVP WTB202
Agenda What is PowerShell Why do developers care Development scenarios and examples PowerShell Community Resources Demos – in between
Present: Windows PowerShell New command-line shell and scripting language As interactive and composable as BASH/KSH As programmatic as Perl/Python/Ruby As production oriented as AS400 CL/VMS DCL Allows access to data stores as easy to access as filesystem
The Difference is OBJECTS! Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table Get-Process Cmdlet Common Windows PowerShell Parser Windows PowerShell Pipeline Processor Where Cmdlet Sort Cmdlet Format Cmdlet
PowerShell Architecture User Experience ShellLanguageDebugger Engine APIsExecution ContextObject Mgr Managed Elements CmdletsWMICOM.NETXMLADOADSINative Commands
State Of The Software Phenomenal rate of adoption Over 2 million downloads in less than 18 months Windows XP, Windows Vista, Windows 7, Windows Server 2003 and 2008 Adopted by Exchange, SQL, SCOM, SCVMM, and SCDPM CEC 2009 requirement Dozens of 3 rd party tools, ISVs, and partners Citrix, VMWare, Websphere, etc Strong community engagement, 27 PowerShell MVPs
PowerShell Engine Exchange cmdlets Configuration Data Access AD Registry Meta base MAPI Store Process boundary E2007Management Architecture Early-bound objs WinForms ADO.Net PowerShell Data Provider WinForms CLI GUI Setup
Forms of Scripting Scripts Filters Functions Script 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
A note on Strict mode – In the shell Allows Typo’s to be caught INSIDE the shell (no IDE) PowerShell v1 Set-PSDebug –strict PowerShell V2 Set-StrictMode –version 1 or Set-StrictMode – version 2.
Productivity Exchange 2003 (VBScript)E2k7 (PowerShell Script) Mailbox Statistics Set listExchange_Mailboxs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\COMPUTERNAME\ROOT\MicrosoftExchangeV2"). InstancesOf("Exchange_Mailbox") 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 get-mailboxstatistics –server $servername 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) move-storagegrouppath -identity “First Storage Group“ –log "C:\newlogPath” Recipient Mgmt Dim objMailbox As CDOEXM.IMailboxStore Set objMailbox = GetObject("LDAP://" + DCServer + "CN=FOO,CN=users," + DomainName) objMailbox.Creat box "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 enabl box -identity domain\FOO –database “First Storage Group\Private MDB”
Why Do Developer Care? Everybody's doing it Powershell is based on.net - chances are if you're in this room you're using.net today Can run.Net code inside PowerShell Can run PowerShell inside managed code Better visibility into the Object Model Find all the instances of a content type in a Site Automated or repetitive tasks Add a web part to a page on 500 sites Faster Development Cycle
Developing Faster Traditional Development Time wasted during Testing PowerShell /.NET Hybrid Development ‘Risky’ development done in PoSH Code converted to.NET (C#/VB) Shorter Deploy/Test Cycle CodeCompileDeployTest Prototyp e (PoSH) CodeCompileDeployTest CodeCompileDeploy
.Net calls inside PowerShell PowerShell is.Net based and has full access to the entire.Net stack Easy to do, direct calls with no need to initialise or wrap
PowerShell INSIDE managed Code PowerShell can be used inside C# Take advantage of PowerShell CMDlets and save coding time Build Winforms GUI’s on top of PowerShell More……
How to write a CMDlet Either as a PowerShell function – shell code us/library/dd aspx Or a.net CMDLET – (compiled code) us/library/dd878294(VS.85).aspx
PowerShellCommunity.org Forums Cmdlet Library Blogs Wiki Script Repository Software Directory User Group Outreach
PowerScripting Podcast Hosts: Jonathan Walz & Hal Rottenberg Online at PowerScripting.netPowerScripting.net Weekly dose of News, Resources, Interviews, Tips and more!
PowerShell Tools PowerGui.org – Free PowerShell IDE with intellisense, code snippets and built in debugging PowerTab – intellisense INSIDE the shell pages/powertab.aspx pages/powertab.aspx
Virtual User Group Marco Shaw runs a monthly user’s group meeting online using Microsoft Live Meeting Interviews Q&A with experts Check news for upcoming events and Marco’s get-powershellblog (marcoshaw.blogspot.com) get-powershellblog
PowerShell Newsgroup Use NNTP server msnews.microsoft.com or web portal Group name: microsoft.public.windows.powershell
#powershell IRC Chat Room Freenode IRC network: irc.freenode.net Web client at powershelllive.com/irc powershelllive.com/irc Only for MVPs and cool people Free real-time scripting advice
Microsoft Resources PowerShell Team Blog blogs.msdn.com/powershell blogs.msdn.com/powershell Scripting Guys Script Center microsoft.com/technet/scriptcenter microsoft.com/technet/scriptcenter Hub for official documentation PowerShell Tip of the Week The Windows PowerShell Toolbox Script repository and other goodies
Community Resources Newsgroup: Microsoft.Public.Windows.PowerShellMicrosoft.Public.Windows.PowerShell Team blog: PowerShell Community: Channel 9: Wiki: Script Center: CodePlex: Books PowerShell in Action by Bruce Payette Windows PowerShell Cookbook by Lee Holmes Professional Windows PowerShell Programming Many others…
International Content & Community Resources for IT Professionals Resources for Developers Microsoft Certification & Training Resources Resources Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings from Tech-Ed website. These will only be available after the event. Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings from Tech-Ed website. These will only be available after the event. Tech ·Ed Africa 2009 sessions will be made available for download the week after the event from:
Related Content Breakout Sessions (session codes and titles) Whiteboard Sessions (session codes and titles) Hands-on Labs (session codes and titles) Required Slide Speakers, please list the Breakout Sessions, TLC Interactive Theaters and Labs that are related to your session. Any queries, please check with your Track Owner. Required Slide Speakers, please list the Breakout Sessions, TLC Interactive Theaters and Labs that are related to your session. Any queries, please check with your Track Owner.
Track Resources Resource 1 Resource 2 Resource 3 Resource 4 Required Slide Track Owners to provide guidance. Please address any queries to your track owners. Required Slide Track Owners to provide guidance. Please address any queries to your track owners.
Required Slide Complete a session evaluation and enter to win! 10 pairs of MP3 sunglasses to be won
© 2009 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. Required Slide