Table of contents
Pre-requisites
To modify the module, you will need git. You can use scoop to install it. Scoop will also allow you to install vscode that is the preferred development environment.
Getting started
To modify the module, first fork it on github and in clone your copy in your local modules directory:
❯ New-Item -Path $env:USERPROFILE\Documents\WindowsPowerShell\Modules -Force | Out-Null
❯ cd $env:USERPROFILE\Documents\WindowsPowerShell\Modules\
❯ git clone https://github.com/<yourusername>/PowerShell-Wsl-Manager Wsl-Manager
The source code of the module is located in the Wsl-Manager.psm1
file. After a modification, you need to ensure that the previous version is not loaded in memory by unloading the module with:
❯ Remove-Module Wsl-Manager
❯
The loading of the new version is done automatically.
Adding a new Exported cmdlet
To add a new cmdlet, you need to first create the function in Wsl-Manager.psm1
:
function <approved_verb>-Wsl {
<#
.SYNOPSIS
...
#>
[CmdletBinding()]
param(
...
)
}
PowerShell is picky about cmdlet verbs. The list is available here.
Then at the end of the file, export the function:
Export-ModuleMember <approved_verb>-Wsl
You also need to add the cmdlet to the FunctionsToExport
property of the hashtable in the Wsl-Manager.psd1
file:
FunctionsToExport = @("Install-Wsl", "Uninstall-Wsl", "Export-Wsl", "Get-WslRootFS", "Get-Wsl", "Invoke-Wsl", "<approved_verb>-Wsl")
Then by removing the module, you are able to test the cmdlet:
❯ Remove-Module Wsl-Manager
❯ <approved_verb>-Wsl ...