I have a module, let me call it xyz.ps.core
. It exports a function - Get-PullRequestsFromCommitIds
I fixed a bug in the function, republished the module, reinstalled and reimported it and yet the function still refers to the old version of the module.
Please, observe:
C:\xyz\tip [master ≡]> Get-Command Get-PullRequestsFromCommitIds | ft -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
Function Get-PullRequestsFromCommitIds 1.0.19107.4 xyz.ps.core
As you can see, the function is from version 1.0.19107.4
C:\xyz\tip [master ≡]> get-module xyz.ps.core | ft -AutoSize
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0.19107.7 xyz.ps.core {Assert-ExtractionDestFolder, Assert-PullRequestMatchesFolder, Backup-Database, Connect-OctopusToTfs...}
C:\xyz\tip [master ≡]> get-module xyz.ps.core -ListAvailable | ft -AutoSize
Directory: C:\Users\mkharitonov\Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0.19107.7 xyz.PS.Core {Assert-ExtractionDestFolder, Assert-PullRequestMatchesFolder, Backup-Database, Connect-OctopusToTfs...}
But the module version is already on 1.0.19107.7
. But OK, I have a function that refreshes the module, even if it is already installed to the same version:
C:\xyz\tip [master ≡]> (get-command Use-Module).ScriptBlock
param([Parameter(Mandatory)]$Name)
if ($VerbosePreference -ne 'Continue')
{
Write-Host -ForegroundColor Cyan -NoNewline "Using the latest version of $Name ... "
}
Write-Verbose "Uninstalling all the versions of $Name ..."
Uninstall-Module $Name -AllVersions -Force -ErrorAction SilentlyContinue
Remove-Module $Name -Force -ErrorAction SilentlyContinue
Write-Verbose "Installing the latest version of $Name ..."
Install-Module $Name -Scope CurrentUser -Force
Write-Verbose "Importing $Name into the current session ..."
Import-Module $Name -Force
if ($VerbosePreference -ne 'Continue')
{
Write-Host -ForegroundColor Cyan (Get-Module $Name).Version
}
Let us use it now:
C:\xyz\tip [master ≡]> use-module xyz.ps.core
Using the latest version of xyz.ps.core ... 1.0.19107.7
Let us check the function source:
C:\xyz\tip [master ≡]> Get-Command Get-PullRequestsFromCommitIds | ft -AutoSize
CommandType Name Version Source
----------- ---- ------- ------
Function Get-PullRequestsFromCommitIds 1.0.19107.4 xyz.ps.core
Still the old one. Notice, that in a new Powershell window the function is taken from the current version of the module.
Is it possible to refresh the function without closing powershell?