Power Shell For Developers Nicolas Blank Zlatan Dzinic
Power. Shell For Developers Nicolas Blank – Zlatan Dzinic Exchange & Share. Point MVP WTB 202
Agenda What is Power. Shell Why do developers care Development scenarios and examples Power. Shell Community Resources Demos – in between
Present: Windows Power. Shell New command-line shell and scripting language • • As interactive and composable as BASH/KSH As programmatic as Perl/Python/Ruby As production oriented as AS 400 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 Common Windows Power. Shell Parser Format Cmdlet Sort Cmdlet Where Cmdlet Get-Process Cmdlet Windows Power. Shell Pipeline Processor
Power. Shell Architecture User Experience Engine Managed Elements Cmdlets Shell APIs WMI COM Language Execution Context . NET XML ADO Debugger Object Mgr ADSI Native Commands
demo
Millions State Of The Software Phenomenal rate of adoption Over 2 million downloads in less than 18 months Power. Shell Downloads 2. 5 Windows XP, Windows Vista, Windows 7, Windows Server 2003 and 2008 Shipped with Windows Server 2008 2 Adopted by Exchange, SQL, SCOM, SCVMM, and SCDPM 1. 5 CEC 2009 requirement Dozens of 3 rd party tools, ISVs, and partners 1 Citrix, VMWare, Websphere, etc 0. 5 Strong community engagement, 27 Power. Shell MVPs 0 M -08 ar 7 -08 Jan v-0 No 07 p. Se 7 l-0 Ju -07 ay -07 ar M M -07 Jan 6 v-0 No
E 2007 Management Architecture GUI CLI Setup Win. Forms ADO. Net Early-bound objs Power. Shell Data Provider Power. Shell Engine Exchange cmdlets Configuration Data Access Process boundary MAPI Store Registry AD Meta base
Forms of Scripting • • Scripts Filters Functions Script Cmdlets [New in V 2]
Styles of Scripting 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) Power. Shell v 1 Set-PSDebug –strict Power. Shell V 2 Set-Strict. Mode –version 1 or Set-Strict. Mode – version 2.
Productivity Mailbox Statistics Exchange 2003 (VBScript) E 2 k 7 (Power. Shell Script) Set list. Exchange_Mailboxs = Get. Object("winmgmts: {impersonation. Level=impersonate}!\COMPUTERNAMEROOTMicrosoft. Exchange. V 2"). Instances. Of("Exchange_Mailbox") get-mailboxstatistics –server $servername For Each obj. Exchange_Mailbox in list. Exchange_Mailboxs WScript. echo "Assoc. Content. Count =” + obj. Exchange_Mailbox. Assoc. Content. Count WScript. echo " Date. Discovered. Absent. In. DS =” + obj. Exchange_Mailbox. Date. Discovered. Absent. In. DS WScript. echo " Deleted. Message. Size. Extended =” + obj. Exchange_Mailbox. Deleted. Message. Size. Extended WScript. echo " Last. Logged. On. User. Account =” + obj. Exchange_Mailbox. Last. Logged. On. User. Account WScript. echo " Last. Logoff. Time =” + obj. Exchange_Mailbox. Last. Logoff. Time WScript. echo " Last. Logon. Time =” + obj. Exchange_Mailbox. Last. Logon. Time WScript. echo " Legacy. DN =” + obj. Exchange_Mailbox. Legacy. DN WScript. echo " Mailbox. Display. Name =” + obj. Exchange_Mailbox. Display. Name WScript. echo " Mailbox. GUID =” + obj. Exchange_Mailbox. GUID WScript. echo " Server. Name =” + obj. Exchange_Mailbox. Server. Name WScript. echo " Size =” + obj. Exchange_Mailbox. Size WScript. echo " Storage. Group. Name =” + obj. Exchange_Mailbox. Storage. Group. Name WScript. echo " Storage. Limit. Info =” + obj. Exchange_Mailbox. Storage. Limit. Info WScript. echo " Store. Name =” + obj. Exchange_Mailbox. Store. Name WScript. echo " Total. Items =” + obj. Exchange_Mailbox. Total. Items Next Database Mgmt Dim Stor. Group as New CDOEXM. Storage. Group Stor. Group. Data. Source. Open "LDAP: //" + DCServer + "/ CN=First Storage Group, CN=Information. Store, CN=" + Server + ", CN=Servers, CN=First Administrative Group, CN=Administrative Groups, CN=First Organization, CN=Microsoft Exchange, CN=Services, CN=Configuration, " + Domain. Name Stor. Group. Move. Log. Files("C: newlog. Path", 0) Recipient Mgmt Dim obj. Mailbox As CDOEXM. IMailbox. Store Set obj. Mailbox = Get. Object("LDAP: //" + DCServer + "CN=FOO, CN=users, " + Domain. Name) obj. Mailbox. Create. Mailbox "LDAP: //" + DCServer + "/CN=Private MDB, CN=First Storage Group, CN=Information. Store, CN=" + Server + ", CN=Servers, CN=First Administrative Group, CN=Administrative Groups, CN=First Organization, CN=Microsoft Exchange, CN=Services, CN=Configuration, " + Domain. Name move-storagegrouppath -identity “First Storage Group“ –log "C: newlog. Path” enable-mailbox -identity domainFOO –database “First Storage GroupPrivate 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 CEC @MS Can run. Net code inside Power. Shell Can run Power. Shell 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 Code Compile Deploy Test Code Compile Deploy Power. Shell /. NET Hybrid Development ‘Risky’ development done in Po. SH Code converted to. NET (C#/VB) Shorter Deploy/Test Cycle Prototype (Po. SH) Code Compile Deploy Test
. Net calls inside Power. Shell is. Net based and has full access to the entire. Net stack Easy to do, direct calls with no need to initialise or wrap
Demo: Calling. Net libraries inside Power. Shell
Power. Shell INSIDE managed Code Power. Shell can be used inside C# Take advantage of Power. Shell CMDlets and save coding time Build Winforms GUI’s on top of Power. Shell More……
Demo: Power. Shell INSIDE managed Code
How to write a CMDlet Either as a Power. Shell function – shell code http: //technet. microsoft. com/enus/library/dd 315326. aspx Or a. net CMDLET – (compiled code) http: //msdn. microsoft. com/enus/library/dd 878294(VS. 85). aspx
Power. Shell Community Resources
Power. Shell. Community. org Forums Cmdlet Library Blogs Wiki Script Repository Software Directory User Group Outreach
Power. Scripting Podcast Hosts: Jonathan Walz & Hal Rottenberg Online at Power. Scripting. net Weekly dose of News, Resources, Interviews, Tips and more!
Power. Shell Tools Power. Gui. org – Free Power. Shell IDE with intellisense, code snippets and built in debugging Power. Tab – intellisense INSIDE the shell http: //thepowershellguy. com/blogs/posh/ 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)
Power. Shell 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 Only for MVPs and cool people Free real-time scripting advice
Microsoft Resources Power. Shell Team Blog blogs. msdn. com/powershell Scripting Guys Script Center microsoft. com/technet/scriptcenter Hub for official documentation Power. Shell Tip of the Week The Windows Power. Shell Toolbox Script repository and other goodies
Community Resources Newsgroup: Microsoft. Public. Windows. Power. Shell Team blog: http: //blogs. msdn. com/Power. Shell Community: http: //www. powershellcommunity. org Channel 9: http: //channel 9. msdn. com/tags/Power. Shell Wiki: http: //channel 9. msdn. com/wiki/default. aspx/Channel 9. Windows. Power. Shell. Wiki Script Center: http: //www. microsoft. com/technet/scriptcenter/hubs/msh. mspx Code. Plex: http: //codeplex. com/Project. Directory. aspx? Tag. Name=powershell Books Power. Shell in Action by Bruce Payette http: //manning. com/powershell Windows Power. Shell Cookbook by Lee Holmes http: //www. oreilly. com/catalog/9780596528492/index. html Professional Windows Power. Shell Programming http: //www. wrox. com/Wiley. CDA/Wrox. Title/product. Cd-0470173939. html Many others…
question & answer
Resources Tech·Ed Africa 2009 sessions will be made available for download the week after the event from: www. tech-ed. co. za www. microsoft. com/teched www. microsoft. com/learning International Content & Community Microsoft Certification & Training Resources http: //microsoft. com/technet http: //microsoft. com/msdn Resources for IT Professionals Resources for Developers
Related Content Breakout Sessions (session codes and titles) Whiteboard Sessions (session codes and titles) Hands-on Labs (session codes and titles)
Track Resources Resource 1 Resource 2 Resource 3 Resource 4
10 pairs of MP 3 sunglasses to be won Complete a session evaluation and enter to win!
© 2009 Microsoft Corporation. All rights reserved. Microsoft, 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.
- Slides: 35