PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
475 stars 90 forks source link

Find-PSResource -IncludeDependencies differs from actual Install-PSResource result? #1639

Open S-dn-Y opened 2 months ago

S-dn-Y commented 2 months ago

Prerequisites

Steps to reproduce

When invoking Find-PSResource with the -IncludeDendencies switch I see different results compared to what Install-PSResource is actually doing. I'm trying to catch what Install-PSResource would do when our pipeline tries to install a module that is already installed. I want to clean up old versions (even if this module is already installed) to keep our environment tidy but this requires me to know what Install-PSResource would install. I used to invoke Install-PSResource with the -Reinstall -PassThru switches but the Az modules installs quite a bit of prerequisites so it introduces more chance of pipeline failures (proxy timeouts etc) that I'd rather just check the prerequisites. Therefore I started using Find-PSResource with the -IncludeDependencies switch, expecting it to give me what I need, but it apparently resolves every dependency of every module and therefore duplicates a Az.Accounts 25 times because a lot of the module apparently specify a different version dependency, but should Find-PSResource not give me back what Install-PSResource would result in though?

Expected behavior

PS C:\Windows\system32> (Find-PSResource -Name Az -IncludeDependencies | Group-Object -Property Name).Where({ $_.Name -eq 'Az.Accounts' })

Count Name                      Group
----- ----                      -----
   1 Az.Accounts               {Microsoft.PowerShell.PSResourceGet.UtilClasses.PSResourceInfo

PS C:\Windows\system32> (Install-PSResource -Name Az -Scope AllUsers -TrustRepository -Reinstall -PassThru | Group-Object -Property Name).Where({ $_.Name -eq 'Az.Accounts' })

Count Name                      Group
----- ----                      -----
    1 Az.Accounts               {Microsoft.PowerShell.PSResourceGet.UtilClasses.PSResourceInfo}

Actual behavior

PS C:\Windows\system32> (Find-PSResource -Name Az -IncludeDependencies | Group-Object -Property Name).Where({ $_.Name -eq 'Az.Accounts' })

Count Name                      Group
----- ----                      -----
   25 Az.Accounts               {Microsoft.PowerShell.PSResourceGet.UtilClasses.PSResourceInfo, Microsoft.PowerShell.PSResourceGet.UtilClasses.PSResourceInfo, Micr...

PS C:\Windows\system32> (Install-PSResource -Name Az -Scope AllUsers -TrustRepository -Reinstall -PassThru | Group-Object -Property Name).Where({ $_.Name -eq 'Az.Accounts' })

Count Name                      Group
----- ----                      -----
    1 Az.Accounts               {Microsoft.PowerShell.PSResourceGet.UtilClasses.PSResourceInfo}

Error details

No response

Environment data

PS C:\Windows\system32> Get-Module Microsoft.PowerShell.PSResourceGet; $PSVersionTable | Format-Table

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     1.0.4.1    Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceR...

Name                           Value
----                           -----
PSVersion                      5.1.20348.2400
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.2400
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visuals

No response

anamnavi commented 2 months ago

@S-dn-Y thanks for creating this issue, we'll take a look into this behavior!