Creating a module

Microsoft's definition of a module is that it is "a package that contains PowerShell members, such as cmdlets, providers, functions, workflows, variables, and aliases."

I can create a simple module by running this code.

$MyModulePath = "C:\Users\$env:USERNAME\Documents\PowerShell\Modules\HelloWorld"

$MyModule = @"
# HelloWorld.PSM1
Function Get-HelloWorld {
 "Hello World from JOR"
}
"@

New-Item -Path $MyModulePath -ItemType Directory -Force | Out-Null
$MyModule | Out-File -FilePath $MyModulePath\HelloWorld.PSM1
Get-Module -Name HelloWorld -ListAvailable

My console displays

I check that the file has been created.

Change directory to HelloWorld and examine the file.

And now I can run the module Get-HelloWorld

Last updated