PSResourceGet
PSResourceGet copied to clipboard
Install-PSResource fails to detect that module is already installed
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest released version
- [X] Search the existing issues.
Steps to reproduce
I noticed a discrepancy in the behavior of Install-Module vs Install-PSResource on Windows Server 2022 / Powershell 7.4.
With Install-Module IISAdministration
, IISAdministration is not installed as it detects it is already installed (Expected behavior). Whereas Install-PSResource
does install the version from the Powershell Gallery.
Install-PSResource Steps
Install-PSResource IISAdministration -Verbose
Import-Module IISAdministration -Verbose
Yields:
VERBOSE: All paths to search: 'C:\Users\azureuser\Documents\PowerShell\Scripts'
VERBOSE: Retrieving directories in the path 'C:\Users\azureuser\Documents\PowerShell\Modules'
VERBOSE: Retrieving directories in the path 'C:\Users\azureuser\Documents\PowerShell\Scripts'
VERBOSE: Attempting to search for packages in 'PSGallery'
VERBOSE: Checking if untrusted repository should be used
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its Trusted value by
running the Set-PSResourceRepository cmdlet. Are you sure you want to install the PSResource from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
VERBOSE: Performing the operation "Install-PSResource" on target "Package to install: 'IISAdministration', version: '1.1.0'".
VERBOSE: Performing the operation "Install-PSResource" on target "Exit ShouldProcess".
VERBOSE: Installation source path is: 'C:\Users\azureuser\AppData\Local\Temp\2\4690b565-d6a9-4bcc-9a7d-91410f8bb39b\iisadministration\1.1.0.0'
VERBOSE: Installation destination path is: 'C:\Users\azureuser\Documents\PowerShell\Modules\IISAdministration\1.1.0.0'
VERBOSE: Attempting to move 'C:\Users\azureuser\AppData\Local\Temp\2\4690b565-d6a9-4bcc-9a7d-91410f8bb39b\iisadministration\1.1.0.0' to 'C:\Users\azureuser\Documents\PowerShell\Modules\IISAdministration\1.1.0.0'
VERBOSE: Successfully installed package 'IISAdministration' to location 'C:\Users\azureuser\Documents\PowerShell\Modules'
VERBOSE: Attempting to delete 'C:\Users\azureuser\AppData\Local\Temp\2\4690b565-d6a9-4bcc-9a7d-91410f8bb39b'
VERBOSE: Successfully deleted 'C:\Users\azureuser\AppData\Local\Temp\2\4690b565-d6a9-4bcc-9a7d-91410f8bb39b'
And:
PS C:\Users\azureuser> Import-Module -Name IISAdministration -verbose
VERBOSE: Loading module from path 'C:\Users\azureuser\Documents\PowerShell\Modules\IISAdministration\1.1.0.0\IISAdministration.psd1'.
VERBOSE: Loading 'TypesToProcess' from path 'C:\Users\azureuser\Documents\PowerShell\Modules\IISAdministration\1.1.0.0\iiscommands.types.ps1xml'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\azureuser\Documents\PowerShell\Modules\IISAdministration\1.1.0.0\iiscommands.format.ps1xml'.
VERBOSE: Populating RepositorySourceLocation property for module IISAdministration.
VERBOSE: Loading module from path 'C:\Users\azureuser\Documents\PowerShell\Modules\IISAdministration\1.1.0.0\Microsoft.IIS.Powershell.Commands.dll'.
Import-Module: Could not load file or assembly 'Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Install-Module Steps
For reference here is the behavior with Install-Module
Install-Module IISAdministration -Verbose
Import-Module IISAdministration -PassThru | select Path
Yields:
PS C:\Users\azureuser> Install-Module IISAdministration -Verbose
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified. PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='IISAdministration'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'IISAdministration'.
VERBOSE: Performing the operation "Install-Module" on target "Version '1.1.0.0' of module 'IISAdministration'".
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
VERBOSE: The installation scope is specified to be 'CurrentUser'.
VERBOSE: The specified module will be installed in 'C:\Users\azureuser\Documents\PowerShell\Modules'.
VERBOSE: Version '1.1.0.0' of module 'IISAdministration' is already installed at 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\IISAdministration'.
PS C:\Users\azureuser> Import-Module IISAdministration -PassThru | select Path
Path
----
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\IISAdministration\iisadministration.psm1
I think this is happening because PSResourceGet is not searching in C:\Windows\system32\WindowsPowerShell\v1.0\Modules.
Actually this also happens in Windows Powershell 5.1 as well:
PS C:\Users\azureuser> Install-PSResource IISAdministration -Verbose
VERBOSE: All paths to search: 'C:\Users\azureuser\Documents\WindowsPowerShell\Modules'
VERBOSE: All paths to search: 'C:\Users\azureuser\Documents\WindowsPowerShell\Scripts'
VERBOSE: Retrieving directories in the path 'C:\Users\azureuser\Documents\WindowsPowerShell\Modules'
VERBOSE: Retrieving directories in the path 'C:\Users\azureuser\Documents\WindowsPowerShell\Scripts'
In this particular instance this is problematic because the IISAdministration Nuget package has not been updated in years and it is packaged incorrectly / missing the WebAdministration.dll as described in this issue
I believe the Install-Module behavior is the correct one (especially since I didn't use AllowClobber)
Expected behavior
VERBOSE: Version '1.1.0.0' of module 'IISAdministration' is already installed at 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\IISAdministration'
Actual behavior
VERBOSE: Successfully installed package 'IISAdministration' to location 'C:\Users\azureuser\Documents\PowerShell\Modules'
Error details
Import-Module: Could not load file or assembly 'Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Environment data
Name Value
---- -----
PSVersion 7.4.0
PSEdition Core
GitCommitId 7.4.0
OS Microsoft Windows 10.0.20348
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response