Created
January 28, 2022 19:33
-
-
Save nickadam/ffbbd67aad81cd17b7baa21065984454 to your computer and use it in GitHub Desktop.
Install a powershell module locally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make a local repository to "publish" and "install" from | |
$PSRepository = (Join-Path -Path $HOME -ChildPath 'PSRepository') | |
mkdir $PSRepository | |
Register-PSRepository -Name 'local' -SourceLocation $PSRepository -PublishLocation $PSRepository -InstallationPolicy Trusted | |
# Make a module | |
mkdir .\MyModule | |
New-Item .\MyModule\Mine.psm1 | |
New-ModuleManifest .\MyModule\Mine.psd1 -RootModule Mine.psm1 -Description 'MyModule' | |
# add functions or whatever to Mine.psm1 | |
@" | |
function Get-Mine { | |
"This is mine!" | |
} | |
"@ | Out-File .\MyModule\Mine.psm1 | |
# Publish the module | |
Publish-Module -Name '.\MyModule\Mine.psd1' -Repository 'local' | |
# Install the module | |
Install-Module -Repository 'local' Mine | |
# Now your functions are available all the time without the need to import | |
# update your modules | |
@" | |
function Get-Mine { | |
"This is mine!" | |
} | |
function Get-MoreMine { | |
"This is also mine!" | |
} | |
"@ | Out-File .\MyModule\Mine.psm1 | |
# update mainfest | |
Update-ModuleManifest .\MyModule\Mine.psd1 -ModuleVersion 0.0.2 | |
# Publish the module | |
Publish-Module -Name '.\MyModule\Mine.psd1' -Repository 'local' | |
# Install the module | |
Install-Module -Repository 'local' Mine -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out you do not need to use a PSRepository, ModuleManifest, or even a subdirectory for the version number of the powershell modules. All that's required is the module filename sit in a subdirectory of the same name. Powershell will parse through the directories in $env:PSModulePath to resolve your cmdlets.