240 likes | 447 Views
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
E N D
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 • Additional Download • Capable of Spreading Malware • Maybe there’s a reason I’m not in Sales
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!”
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()));
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
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) { $_ } }
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
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“]
Providers • Act like a ‘Drive’ • Implement actions like • Get/Set/Delete Item • Some Available Providers • Active Directory • SharePoint (v2) • SQL Server • Access
Hosting PowerShell • Two Levels of Difficulty • Execute Commands • Host the UI
Hosting PowerShell • Execute Commands • The easiest option • RunspaceInvoke.Invoke(“dir”) • Returns PSObject(s)
Hosting PowerShell • Host the UI • Very difficult • Can provide immense amounts of power • Examples: • PowerShellPlus • PoshConsole
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
Vendors • ShellTools (PowerShellPlus, PowerShell Analyzer) • http://www.shelltools.net/ • Quest Software • http://www.quest.com/powershell/ • NetCmdlets • http://www.nsoftware.com/powershell/
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
Thanks! Neil Iversen Inetium JustAddCode.com