Powershell: Create a powershell module


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" = ""

PS D:\myModule> New-ModuleManifest @Params

Create the module file MyModule.psm1

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


Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.