PowerShell for Admins PowerShell for Developers

Writing and Publishing PowerShell Modules

pscookiemonster
2 min read
Share:

Earlier in August we mentioned that modularity and abstraction are quite helpful. PowerShell modules can help enable these concepts.

You might ask “Modules… why can’t I just write a function?” There are a number of benefits to bundling your functions into modules:

  • Simplify code organization
  • Group related functions together
  • Share state between functions, but not with the user
  • Re-use “helper functions” that you don’t want exposed to the user
  • Improve discoverability: Find-Module MyModuleGet-Command -Module MyModule * Simplify distribution: Install-Module MyModule `Where does that last bullet come from?

If you’ve worked with Perl, you’ve probably used CPAN, which archives more than 150,000 modules. Other languages have similar tools, like PyPI for Python, or RubyGems for Ruby.

In the PowerShell world we’ve had a few community alternatives, but nothing official until late 2014, when Microsoft introduced the PowerShell Gallery. The gallery is still under limited preview, with less than 300 modules published.

The PowerShell community can benefit from the PowerShell Gallery through simplified and centralized discovery and distribution. We can find, install, or publish modules with a single command in PowerShell 5. Perhaps some day we will see a vibrant PowerShell community that extends beyond IT administration.

Write and Publish PowerShell Modules

Let’s help build up the PowerShell Gallery. Do you write PowerShell modules at work or at home? Consider open sourcing them on GitHub, and publishing them in the PowerShell Gallery!

If you’re comfortable writing PowerShell functions, but haven’t started writing modules, check out Building a PowerShell Module, where we walk through the creation and publication of a PowerShell module.

Edit: This follow-up shows a simple way to automatically deploy your modules to the gallery.

Cheers!

Related Articles

Oct 8, 2021

ICYMI: PowerShell Week of 08-October-2021

Topics include VMWare, Windows 11, Web Reports and more… Special thanks to Robin Dadswell, Prasoon Karunan V, Kiran Patnayakuni and Kevin Laux How to gather your vCenter inventory data with this VMware PowerShell script by Scott Matteson on 7th October Inventory reports are a common request when administering a VMware vCenter environment. Learn how this VMware PowerShell script can make such requests quick and easy Building a Web Report in PowerShell, use the -Force Luke by Chris Noring on 8th October