Code packaging and distribution

Installed in machine or user context

Get-Module -ListAvailable
Import-Module -Name ThreadJob
Remove-Module -Name ThreadJob
Find-Module -Name PoshRSJob
Install-Module -Name PoshRSJob -Scope CurrentUser

Many modules are still being migrated to PS Core

New code must (at least) be tested on PS Core

What is a module?

Nothing more than a directory

Modules are located in

# PowerShell Core

# Windows PowerShell

Always prefer user scope

Mandatory files

The manifest describes the module (.psd1)

The root module contains the code (.psm1)

    +-- $ModuleName.psd1
    +-- $ModuleName.psm1

The root module is referenced in the manifest

New manifests are generated using New-ModuleManifest

Module manifest

Minimal manifest:

    RootModule = 'MyModule.psm1'
    ModuleVersion = '0.0.1'
    GUID = 'cd0e76ae-1097-47b3-b80b-31c8e0493c13'
    Author = 'Nicholas Dille'
    Copyright = '(c) Nicholas Dille. All rights reserved.'
    Description = 'My helper library'
    FunctionsToExport = @()

Generate a new globally unique ID using New-Guid


Installation dependencies:

Install-Module -Name GoCd -Scope CurrentUser
$GoCdModule = Get-Module -Name GoCd -ListAvailable

Add RequiredModules to module manifest

Dependencies are resolved at install time