Neil Iversen Inetium justaddcode.com
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! 3 rd 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()));
Sales Demo
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) { $_ } }
Scripting Demo
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
Type Extension Demo
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“]
Demo: Cmdlet Building
Providers Act like a ‘Drive’ Implement actions like Get/Set/Delete Item Some Available Providers Active Directory SharePoint (v2) SQL Server Access
Demo: OOB Providers
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
Demo: Hosting PowerShell
References PowerShell Community Extensions CmdLet Visual Studio Template eating-a-windows-powershell-cmdlet-using-the- visual-studio-windows-powershell-templates.aspx eating-a-windows-powershell-cmdlet-using-the- visual-studio-windows-powershell-templates.aspx Debugging Techniques bugging-cmdlets.aspx bugging-cmdlets.aspx Windows PowerShell Programmers Guide us/library/ms714674(VS.85).aspx us/library/ms714674(VS.85).aspx
Vendors ShellTools (PowerShellPlus, PowerShell Analyzer) Quest Software NetCmdlets
Questions?
SharePoint Developer? Minneapolis Office Developer Interest Group (MODIG) Next Meeting: April 22, Web Part Development Personalization, Connections, AJAX.net, ToolPane
Thanks! Neil Iversen Inetium JustAddCode.com