An Introduction to PowerShell Modules

17
An Introduction to PowerShell Modules Jonathan Medd

description

An Introduction to PowerShell Modules

Transcript of An Introduction to PowerShell Modules

Page 1: An Introduction to PowerShell Modules

An Introduction to PowerShell Modules

Jonathan Medd

Page 2: An Introduction to PowerShell Modules

How can you distribute additional PowerShell functionality?Snapin – PowerShell v1

Provider or CmdletsNot for your average IT Pro to create

Module – PowerShell v2 (Snapins still available)Provider, Cmdlets, Functions, Variables and

AliasesAny IT Pro can make a module

Page 3: An Introduction to PowerShell Modules

What is a module?Simple as a collection of files containing

functions, scripts etc and possibly other files such as the manifest to make it more professional

Stored within a folder as a subfolder of the Modules location. Can be found via $env:PSModulePath

Contents made accessible to the user via the Import-Module cmdlet

Page 4: An Introduction to PowerShell Modules

Why bother?Makes sharing of groups of functions and

scripts easySimple XCOPY style deployment of the

module folder either internally or publishing to an external website

Make your commonly used functions available to yourself without ‘Profile Bloat’ – they are available as and when you need them from a module

Page 5: An Introduction to PowerShell Modules

Modules can transform you from this:

Page 6: An Introduction to PowerShell Modules

To Superstars with Groupies:

Page 7: An Introduction to PowerShell Modules

More on the module that made that transformation happen later........

Page 8: An Introduction to PowerShell Modules

Buy This Book

Page 9: An Introduction to PowerShell Modules

Making Your First ModuleCreate two functionsSave them into a *.psm1 file to the module

folderImport them for use into your sessionGo!

Yes it is as easy as that

Page 10: An Introduction to PowerShell Modules

Demo – Create a Module

Page 11: An Introduction to PowerShell Modules

Making Your Module More ProfessionalCreate a Module Manifest using New-ModuleManifestInclude Authoring or Version infoSpecify minimum versions of PowerShell

or .NET required for the moduleNest other modulesRun scripts prior to loading the module, e.g.

check for third-party snapin dependenciesCan be created manually Use Test-ModuleManifest to check for

issues

Page 12: An Introduction to PowerShell Modules

Demo – Create The Manifest

Page 13: An Introduction to PowerShell Modules

Modules Make Distributing Your Code Easier

VS

Page 14: An Introduction to PowerShell Modules

Demo – PowerCLIBook Module

Page 15: An Introduction to PowerShell Modules

Other ModulesWindows Server2008 R2 -

>Community Modules

PowerShell Community Extensions

BSonPOSH ModuleSQLPSX

Search on http://www.codeplex.com – currently 50+

Page 16: An Introduction to PowerShell Modules

Demo – TroubleShootingPack Module