Last active
November 5, 2024 08:32
-
-
Save kilasuit/10fd509d2754ee79a2d9d05ffc3ef523 to your computer and use it in GitHub Desktop.
This will always Import the latest Module in a PSModulePath in PowerShell
This file contains hidden or 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
## I know this was at one point needed - but it shouldn't be needed | |
## but see https://github.com/PowerShell/PowerShell/issues/24489 for more info | |
## around if this is still needed in future | |
function Import-LatestModule { | |
[CmdletBinding()] | |
[Alias('iplmo')] | |
param ( | |
# Parameter help description | |
[Parameter(Mandatory = $true, Position = 0)] | |
[String] | |
$Module | |
) | |
Get-Module $module -ListAvailable | Sort-Object Version -Descending -Top 1 | Import-Module | |
} | |
## An alternative would be to search all filesystem drives for a folder matching the module name | |
## & then within that folder any similarly named PowerShell files, which can include psd1, psm1, dll, CDXML etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment