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

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

$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

PS D:\myModule> Get-Verb

The try to load the module

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

Michael

Leave a Reply Cancel reply