1 / 24

Extending PowerShell

Neil Iversen Inetium justaddcode.com. Extending PowerShell. The Plan. PowerShell Sales Pitch Creating Scripts Type Extensions Rolling your own Cmdlets Other Extensionibility Providers Hosting PowerShell. PowerShell Sales Pitch. Looks like DOS No Mouse Support No Intellisense

cairbre
Télécharger la présentation

Extending PowerShell

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Neil Iversen Inetium justaddcode.com Extending PowerShell

  2. The Plan • PowerShell Sales Pitch • Creating Scripts • Type Extensions • Rolling your own Cmdlets • Other Extensionibility • Providers • Hosting PowerShell

  3. PowerShell Sales Pitch • Looks like DOS • No Mouse Support • No Intellisense • Additional Download • Capable of Spreading Malware • Maybe there’s a reason I’m not in Sales

  4. Revised PowerShell Sales Pitch • Still Looks like DOS • But much more powerful • Now with Extra Tab Support! • 3rd Party Support • Bundled with Win2k8 • Built in security measures • Code Signing is Possible • 9 out of 10 Dentists agree: • “PowerShell makes teeth whiter!”

  5. Still Not Sold? • It doesn’t have to look ugly • Full .NET Access • Loosely typed language • The Pipeline • Pass as full .NET objects • PowerShell: Command1 |Command2| Command3 • C# Equivalent: Command3(Command2(Command1()));

  6. Sales Demo

  7. Functional Programming • Familiar Constructs • Function • If/then • For/while • Store in PS1 files • Run with & ‘path\file.ps1’ • Include with . ‘path\file.ps1’ • Accepts Arguments • Function name ($val1, $val2) • Or $args array

  8. Filters • Similar to Functions • Can still take arguments • Runtime Difference • Functions: Run Once In Pipeline • Filters: Run for Each Pipeline object • Biggest disadvantage: No ‘initialize’ stage filter filesonly { if(-not $_.PSIsContainer) { $_ } }

  9. Scripting Demo

  10. Type Extensions • Take advantage of loose typing • Extend existing types • Or Create your Own • Using Add-Member • Fields • Properties • Methods • Make Permanent with ps1xml • Update-TypeData –prepend MyNewTypes.ps1xml

  11. Type Extension Demo

  12. Creating a Cmdlet • Compiled and Portable • Bundled together in a Snapin • Inherit from CmdLet • WriteObject() • Sends data back to the Pipeline • [Cmdlet(VerbsCommon.Get, “CmdletName“]

  13. Demo: Cmdlet Building

  14. Providers • Act like a ‘Drive’ • Implement actions like • Get/Set/Delete Item • Some Available Providers • Active Directory • SharePoint (v2) • SQL Server • Access

  15. Demo: OOB Providers

  16. Hosting PowerShell • Two Levels of Difficulty • Execute Commands • Host the UI

  17. Hosting PowerShell • Execute Commands • The easiest option • RunspaceInvoke.Invoke(“dir”) • Returns PSObject(s)

  18. Hosting PowerShell • Host the UI • Very difficult • Can provide immense amounts of power • Examples: • PowerShellPlus • PoshConsole

  19. Demo: Hosting PowerShell

  20. References • PowerShell Community Extensions • http://www.codeplex.com/PowerShellCX • CmdLet Visual Studio Template • http://blogs.msdn.com/daiken/archive/2007/02/07/creating-a-windows-powershell-cmdlet-using-the-visual-studio-windows-powershell-templates.aspx • Debugging Techniques • http://blogs.msdn.com/jmstall/archive/2007/03/04/debugging-cmdlets.aspx • Windows PowerShell Programmers Guide • http://msdn2.microsoft.com/en-us/library/ms714674(VS.85).aspx

  21. Vendors • ShellTools (PowerShellPlus, PowerShell Analyzer) • http://www.shelltools.net/ • Quest Software • http://www.quest.com/powershell/ • NetCmdlets • http://www.nsoftware.com/powershell/

  22. Questions?

  23. SharePoint Developer? • Minneapolis Office Developer Interest Group (MODIG) • http://www.sharepointmn.com/modig • Next Meeting: April 22, 5:30pm @Microsoft • Web Part Development • Personalization, Connections, AJAX.net, ToolPane

  24. Thanks! Neil Iversen Inetium JustAddCode.com

More Related