Will Murphy william.w.murphy@gmail.com @williamwmurphy Who am I? Started coding and scripting in 1999. C, C++, BASH Started in IT in 2000 while co-oping in college. Korn Shell and PERL on AIX Written Production solutions in PERL,KSH,BASH, and VB Script Started with PowerShell v1 in 2009. Lead group from 2 out of 8 to 8 out of 11 engineers using PowerShell. What is a Module? Collection of functionalities. Common nouns in cmdlets and functions. Members are not restricted like with snap-ins. Four types of modules Binary (.dlls) .NET compiled code Script (.psm1) collection of advanced functions Manifest (.psd1) no root module, nested modules Dynamic (non persistent) uses New-Module Structure of a Script Module Files Script module file .psm1 –required Manifest file .psd1 Script files .ps1 Format files .format.ps1xml Help files .txt(v2/v3) .cab/.xml(v3) Application libraries .dll Script module file Member definitions or execution of other script files Manifest file Contains script modules file to execute Required components: PowerShell, CLR versions, other modules Metadata: Author, Description Other components to load One file vs. Multiple files One File Multiple Files Pros Fewer files to manage No/Fewer updates to manifest Easier to deploy Cons Distributed development is hard Larger the module, the bigger the file Pros Work in smaller units No reloading module when changing single function Easier distributed development Cons More files to maintain Update manifest and script module every time you add member One file vs. Multiple files Where to Install PSMODULEPATH C:\Windows\System32\WindowsPowerShell\v1.0\Module s C:\Users\(username)\Documents\WindowsPowerShell\M odules Your path Non-Shared: Program files\CompanyName\Application\Module Shared: Program Files\Common Files\Module Where it makes sense C:\Program Files (x86)\CompanyName\PSModules Lesson Learned Be consistent. Function names, parameter names. Common parameters are used the same way. If it’s dangerous, assume that instructions/help won’t be read. Set defaults to help with control execution. -WhatIf is your friend Borrow from the community We have a large, enthusiastic community; and they’re really smart Deployment Options XCOPY,ZIP MSI Pros Copy the folder to the location. Zip the entire folder for distribution. No special tools required. Cons Deployment may require scripting. Version requires inspecting the contents. Can’t update PSMODULEPATH. Pros Single installation file. Can create folder path. Can perform other actions. Silent install allows for easier deployments. Versioning maintained by Windows Installer. Cons Requires tools and knowledge to build MSI. Building MSIs Free and paid tools available. Visual Studio-$$ Includes two options to build MSIs with wizards, but limited flexibility. Option to buy additional tools. WIX – free Flexible and powerful, but can have a steep learning curve. Can integrate with VS. WIX Resources URLs Writing PowerShell Modules http://msdn.microsoft.com/enus/library/windows/desktop/dd878310(v=vs.85).aspx WIX toolset http://wixtoolset.org/