Powershell: Create a powershell module

Hi,

this describes the creation of an powershell module.

Define a manifest and create the mainfest file by New-ModuleManifest

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PS D:\> $Params = @{
        "Path"              = 'MyModule.psd1'
        "Author"            = 'Michael'
        "CompanyName"           = 'My Company'
        "RootModule"            = 'MyModule.psm1'
        "CompatiblePSEditions"      = @('Desktop','Core')
        "FunctionsToExport"         = @('Test-Function1','Test-Function1')
        "CmdletsToExport"       = @()
        "VariablesToExport"         = @('myExportVariable1','myExportVariable2')
        "AliasesToExport"       = @()
        "Description" = 'Description of the module'
        "ModuleVersion" = "1.0.0.0"
    }
 
PS D:\myModule> New-ModuleManifest @Params

Create the module file MyModule.psm1

1
2
3
4
5
6
7
8
9
10
$myExportVariable1="Test"
$myExportVariable2="Test"
function Test-Function1()
{
     write-host "Function1"
}
function Test-Function2()
{
     write-host "Function2"
}

Note: The function names must begin with a valid verb otherwise a warning is shown during the load of the module.

Get-Verb shows a list of valid verbs

1
PS D:\myModule> Get-Verb

The try to load the module

1
PS D:\myModule> Import-Module .\MyModule.psd1

Michael

Leave a Reply