PowerShell Technical Overview

4,033 views

Published on

A technical overview of PowerShell. See http://blogs.msdn.com/allandcp/archive/2009/03/11/powershell-to-the-people-the-aftermath.aspx for more background and resources.

Published in: Technology
  • Be the first to comment

PowerShell Technical Overview

  1. 1. Windows PowerShell: A Technical Overview “ Something old, something new, something borrowed and something blue” Allan da Costa Pinto Windows PowerShell Fanboy Microsoft [email_address] http://blogs.msdn.com/allandcp
  2. 2. For the .NET Developers in the crowd: Increase your .NET Skills with the free Training Kits http://tinyurl.com/6q5jqz
  3. 3. <ul><li>http://msevents.microsoft.com </li></ul><ul><li>Search for Virtual Labs </li></ul><ul><li>Search on PowerShell </li></ul>
  4. 4.  Ricky Buch Program Manager Microsoft Corporation <ul><li> Kevin Michael Woley </li></ul><ul><li>Program Manager </li></ul><ul><li>Microsoft Corporation </li></ul>http://channel9.msdn.com/pdc2008/PC50/
  5. 8. http://blogs.msdn.com/powershell/archive/2009/01/14/windows-7-troubleshooting.aspx
  6. 9. More…
  7. 10. http://channel9.msdn.com/pdc2008/ES14/ ASP.NET on Server Core Integrated PowerShell Provider Integrated FTP and WebDAV New IIS Manager Modules Configuration Logging & Tracing Best Practices Analyzer
  8. 11. http://channel9.msdn.com/pdc2008/ES06/
  9. 12. IIS/WAS Quadrant IIS Manager WF and WCF Frameworks Persistence SQL Persistence Provider Management APIs ( PowerShell command-lets) WF and WCF Management Modules Runtime Databases Persistence schema Monitoring schema Monitoring WF SQL Tracking Provider WCF SQL Tracking Behaviors Messaging Forwarding Service Hosting Durable Timer Service Visual Studio WF and WCF Project Templates Windows Application Server Role Model Deployment to Dublin Discovery Service Dublin adds Dublin enhances Windows/IIS/.NET 4.0 Scale-out & Reliability Discovery & Control Application Monitoring Versioning, Partitioning, Routing System Center App Server SCOM Pack “ It just works!” http://channel9.msdn.com/pdc2008/BB18
  10. 14. http://www.codeplex.com/PSHyperv
  11. 15. http://www-01.ibm.com/support/docview.wss?rs=171&uid=swg24017698
  12. 16. http://halr9000.com/article/716 Costly
  13. 17. I don’t have an iPhone but if I did… http://tinyurl.com/b62o8f
  14. 18. No .NET? Know .NET? <ul><li>Object Oriented scripting language and shell built on .NET Framework </li></ul><ul><li>Backwards Compatible and works with COM, WMI, .NET, XML </li></ul><ul><li>Easy to learn, adopt, automate and extend with a thriving community </li></ul><ul><li>Hosted in other applications (MMC 3.0, custom) </li></ul><ul><li>Available for Windows XP, Windows 2003 and Windows Vista </li></ul><ul><li>In the box with Windows Server 2008, Windows 7 and Windows Server 2008 R2 </li></ul><ul><li>1.0 born in 2006, 2.0 currently in CTP V3 </li></ul>
  15. 19. Exchange 2007 –eq &quot;Much Simpler&quot; Exchange Server 2003 (VBScript) E2K7 (PowerShell one-liner) Mailbox Statistics Set listExchange_Mailboxs = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!OMPUTERNAMEROOTMicrosoftExchangeV2&quot;).InstancesOf(&quot;Exchange_Mailbox&quot;) For Each objExchange_Mailbox in listExchange_Mailboxs WScript.echo &quot;AssocContentCount =” + objExchange_Mailbox.AssocContentCount WScript.echo &quot; DateDiscoveredAbsentInDS =” + objExchange_Mailbox.DateDiscoveredAbsentInDS WScript.echo &quot; DeletedMessageSizeExtended =” + objExchange_Mailbox. DeletedMessageSizeExtended WScript.echo &quot; LastLoggedOnUserAccount =” + objExchange_Mailbox. LastLoggedOnUserAccount WScript.echo &quot; LastLogoffTime =” + objExchange_Mailbox. LastLogoffTime WScript.echo &quot; LastLogonTime =” + objExchange_Mailbox. LastLogonTime WScript.echo &quot; LegacyDN =” + objExchange_Mailbox. LegacyDN WScript.echo &quot; MailboxDisplayName =” + objExchange_Mailbox. MailboxDisplayName WScript.echo &quot; MailboxGUID =” + objExchange_Mailbox. MailboxGUID WScript.echo &quot; ServerName =” + objExchange_Mailbox. ServerName WScript.echo &quot; Size =” + objExchange_Mailbox. Size WScript.echo &quot; StorageGroupName =” + objExchange_Mailbox. StorageGroupName WScript.echo &quot; StorageLimitInfo =” + objExchange_Mailbox. StorageLimitInfo WScript.echo &quot; StoreName =” + objExchange_Mailbox. StoreName WScript.echo &quot; TotalItems =” + objExchange_Mailbox. TotalItems Next get-mailboxstatistics – server $servername Database Mgmt Dim StorGroup as New CDOEXM.StorageGroup StorGroup.DataSource.Open &quot;LDAP://&quot; + DCServer + &quot;/ CN=First Storage Group,CN=InformationStore,CN=&quot; + Server + &quot;,CN=Servers,CN=First Administrative Group, CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services, CN=Configuration,&quot; + DomainName StorGroup.MoveLogFiles(&quot;C: ewlogPath&quot;, 0) move-storagegrouppath -identity “First Storage Group“ – log &quot;C: ewlogPath” Recipient Mgmt Dim objMailbox As CDOEXM.IMailboxStore Set objMailbox = GetObject(&quot;LDAP://&quot; + DCServer + &quot;CN=FOO,CN=users,&quot; + DomainName) objMailbox.CreateMailbox &quot;LDAP://&quot; + DCServer + &quot;/CN=Private MDB,CN=First Storage Group,CN=InformationStore,CN=&quot; + Server + &quot;,CN=Servers,CN=First Administrative Group, CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services, CN=Configuration,&quot; + DomainName enable-mailbox -identity domainFOO – database “First Storage GroupPrivate MDB”
  16. 20. Exchange 2007 Management Architecture CLI GUI Setup Process Boundary Exchange cmdlets Configuration Data Objects/Access PowerShell Data Provider PowerShell Engine Windows Forms Early-bound objs Windows Forms ADO.NET MAPI Store Registry Meta base AD
  17. 21. Get-Command Get-Help Get-Member Get-PSDrive Get the Free eBook and information about the 4 most important CmdLets http://tinyurl.com/powershell4
  18. 22. Anatomy
  19. 23. http://www.flickr.com/photos/ajari/2288043144/
  20. 24. http://www.flickr.com/photos/mnkyhead/3292809/
  21. 25. Verb – Noun <ul><li>Clear – Host </li></ul><ul><li>Set – ExecutionPolicy </li></ul><ul><li>Get – Help </li></ul><ul><li>Write – Debug </li></ul><ul><li>Restart – Computer </li></ul><ul><ul><li>Don’t do this during session, but -whatif you did? </li></ul></ul><ul><li>Drink – Beer </li></ul><ul><ul><li>Do this before session  </li></ul></ul>
  22. 26. http://www.flickr.com/photos/dnorman/2249376120/
  23. 27. http://www.flickr.com/photos/9229859@N02/1951252254/
  24. 28. http://www.flickr.com/photos/adactio/377537734/
  25. 29. The PowerShell pipeline Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table Get-Process Cmdlet Common Windows PowerShell Parser Windows PowerShell Pipeline Processor Where-Object Cmdlet Sort -Object Cmdlet Format-Table Cmdlet Alias Alias
  26. 30. A Review <ul><li>Cmdlets </li></ul><ul><ul><li>Tiny commands </li></ul></ul><ul><ul><li>Composability </li></ul></ul><ul><li>Providers </li></ul><ul><ul><li>Abstraction of drives </li></ul></ul><ul><ul><li>Discoverability </li></ul></ul><ul><li>Snap-ins </li></ul><ul><ul><li>Unit of deployment </li></ul></ul><ul><ul><li>Wraps cmdlets, providers, etc </li></ul></ul>PS C:> Get-Process PS C:> cd HKLM: PS HKLM: > PS C:> add-pssnapin MySnapIn
  27. 31. Modifying the system <ul><li>Support -confirm and -whatif operations </li></ul><ul><ul><li>CmdletAttribute[..., SupportsShouldProcess = true ] </li></ul></ul><ul><ul><li>Call ShouldProcess for initial confirmation </li></ul></ul><ul><ul><ul><li>Are you sure? </li></ul></ul></ul><ul><ul><li>Call ShouldContinue for additional confirmation </li></ul></ul><ul><ul><ul><li>Are you really sure? </li></ul></ul></ul><ul><ul><ul><li>Enable/disable “yes to all” and “no to all” options </li></ul></ul></ul><ul><ul><li>Provide a “force” parameter to bypass these calls </li></ul></ul><ul><li>Specify the impact of the cmdlet </li></ul><ul><ul><li>Allows user to set the confirm sensitivity </li></ul></ul><ul><ul><li>CmdletAttribute[..., ConfirmImpact = ConfirmImpact.High ] </li></ul></ul>
  28. 32. Extending Windows PowerShell <ul><li>Aliases </li></ul><ul><li>Functions </li></ul><ul><li>Cmdlets </li></ul><ul><ul><li>Write them in .NET (v1) </li></ul></ul><ul><ul><li>Write them in PowerShell (v2) </li></ul></ul><ul><li>Providers </li></ul><ul><ul><li>IIS, SQL, Exchange, Yours </li></ul></ul><ul><li>Custom Hosts </li></ul><ul><ul><li>http://blogs.msdn.com/daiken/archive/2007/06/22/hosting-windows-powershell-sample-code.aspx </li></ul></ul>
  29. 33. PowerShell Architecture
  30. 34. PowerShell Architecture Add Creativity Here!
  31. 35. PowerShell V2 Themes
  32. 36. Extended Type System (ETS) <ul><li>Type Adapters provide consistent object access across different technologies </li></ul><ul><ul><li>.NET, COM, WMI, ADSI, XML, ADO </li></ul></ul><ul><li>Allows scripts to be general regardless of “native” object interaction </li></ul><ul><ul><li>Scripts can be based on property names not programming knowledge classes and types </li></ul></ul><ul><li>Object utilities work against all objects </li></ul>http://www.flickr.com/photos/foundphotoslj/449085680/
  33. 37. <ul><li>Shell Defaults </li></ul><ul><li>No scripts run (ExecutionPolicy=Restricted) </li></ul><ul><li>.ps1 is associated with Notepad </li></ul><ul><li>Must provide a path to a script file in order to run it </li></ul><ul><li>You Can Configure </li></ul><ul><li>ExecutionPolicy </li></ul><ul><ul><li>Restricted </li></ul></ul><ul><ul><li>AllSigned </li></ul></ul><ul><ul><li>RemoteSigned </li></ul></ul><ul><ul><li>Unrestricted (No!!!) </li></ul></ul><ul><li>Centrally configurable via Group Policy </li></ul><ul><li>In V2 Constrain Runspaces </li></ul>
  34. 38. Resources! <ul><li>Team blog </li></ul><ul><ul><li>http://blogs.msdn.com/PowerShell/ </li></ul></ul><ul><li>PowerShellCommunity.Org </li></ul><ul><ul><li>http://www.PowershellCommunity.Org </li></ul></ul><ul><li>Channel 9 </li></ul><ul><ul><li>http://channel9.msdn.com/tags/PowerShell </li></ul></ul><ul><ul><li>http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellWiki </li></ul></ul><ul><li>Script Center </li></ul><ul><ul><li>http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx </li></ul></ul><ul><li>CodePlex </li></ul><ul><ul><li>http://codeplex.com/Project/ProjectDirectory.aspx?TagName=powershell </li></ul></ul><ul><li>Books I own </li></ul><ul><ul><li>Manning Press book by PowerShell Dev Lead Bruce Payette: PowerShell in Action </li></ul></ul><ul><ul><ul><li>http://manning.com/powershell/ </li></ul></ul></ul><ul><ul><li>O’Reilly book by PowerShell Dev Lee Holmes – Windows PowerShell Cookbook </li></ul></ul><ul><ul><ul><li>http://www.oreilly.com/catalog/9780596528492/index.html </li></ul></ul></ul><ul><li>Newsgroup: Microsoft.Public.Windows.PowerShell </li></ul>
  35. 39. Out-Thankyou PS C:> Thank you for your time and attention. Good luck in your PowerShell Adventures! Get-Allandcp PS C:> Allan da Costa Pinto Microsoft [email_address] http://blogs.msdn.com/allandcp

×