PSResourceGet
PSResourceGet copied to clipboard
Update-Module does not really update the module
Update-Module only installs a newer version. It does not remove the previous version. This is no different that using Install-Module except that it checks the current installed version an searches for a newer version. That search functionality would be better implemented as a -Update parameter for Install-Module.
Expected Behavior
Update-Module should replace the current version with a new version. Not install the new version side-by-side with the old version.
Possible Solutions
- Deprecate Update-Module and move the search for update functionality into Install-Module.
- Change Update-Module to remove the old version. This needs to be smart enough to remove all old versions of nested modules without breaking dependencies in other installed modules.
Context
Using the verb Update is confusing to customers. They expect the cmdlet to update what they have not install side-by-side. Also, the cmdlet reference does not explain this behavior.
We see this a lot with Azure PowerShell. They release a new version every month. After a few months you can have several versions installed taking up a lot of space.
Your Environment
PS C:\Git> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.15063.296
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.296
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\Git> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.0 chocolateyProfile {TabExpansion, Update-SessionEnvironment, refreshenv}
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Cont...
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 0.7.0 posh-git {Add-PoshGitToProfile, Add-SshKey, Enable-GitColors, Get-Al...
Script 1.2 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PSR...
Script 1.0.0.1 PSYaml {Convert-YAMLtoJSON, ConvertFrom-YAML, ConvertFrom-YAMLDocu...
Script 1.0 sdwheeler.utilities {close-SQLite, ConvertFrom-Base64, convertfrom-htmlencoding...
PS C:\Git> Get-Module -ListAvailable PowerShellGet,PackageManagement
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.1.3.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag...
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag...
Script 1.1.2.0 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
PS C:\Git> Get-PackageProvider
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.207 Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag,...
PowerShellGet 1.1.2.0 PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, I...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
PS C:\Git> Get-PackageProvider -ListAvailable
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.207 Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag,...
PowerShellGet 1.1.2.0 PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, I...
PowerShellGet 1.0.0.1
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
I have hit this same issue with two of my modules (PureStoragePowerShellSDK and PureStoragePowerShellToolkit).
If users have scripts that require modules at X version, And update module replaces the available version then some script written long ago might break.
Maybe there should be a Get-OutdatedModule that could be piped to remove-module. At least the user intended to get rid of versions that way.
Similar problem solutions I've seen would be npm prune. Perhaps a Clear-module could inspect all available modules RequiredModules Version tree and remove only modules that aren't found/older but semver compatible.
But that would only maintain other declared modules, user scripts might break on removal of older modules. And you'd be trusting authors concept of semver.
@JKeithB - We need a way to uninstall a module and all its dependencies. Adding that functionality to Uninstall-Module should be very simple. I wrote the following function to uninstall a module and its dependencies.
function uninstall-modwithdependencies
param(
[string]$module,
[string]$version
)
'Creating list of dependencies...'
$depmods = Find-Module $module -RequiredVersion $version |
select -exp dependencies |
select @{l='name';e={$_.name}},@{l='ver';e={$_.requiredversion}}
foreach ($mod in $depmods) {
'Uninstalling {0}' -f $mod.name
uninstall-module $mod.name -RequiredVersion $mod.ver
}
Uninstall-Module $module -RequiredVersion $version
}
@SydneyhSmith / @SteveL-MSFT if this issue is not completed before PSGet 3.0 GA will it be a breaking change?
@ThomasNieto for 3.0 we are maintaining the behavior of Update, to install the latest version, and not delete older versions... since this has always been the behavior of PowerShellGet this will not be a change...in the future we may address this feature request by adding a parameter to the Update cmdlet that specifies older versions of the module should be uninstalled
| Assert-Duplicate -Near -Fuzzy $_ #581
@ThomasNieto for 3.0 we are maintaining the behavior of Update, to install the latest version, and not delete older versions... since this has always been the behavior of PowerShellGet this will not be a change...in the future we may address this feature request by adding a parameter to the Update cmdlet that specifies older versions of the module should be uninstalled
Would it be possible to change this so that Update-Module does update by default, and install side-by-side when a parameter is added?
I'd argue that the expected behaviour of any update mechanism is to replace the old version with the new one, so this should also be the default for PSGet 3
@danielniccoli have you read the discussion of that over in #581?