PowerShell / PowerShell/PSResourceGet
Don't accept `-Version` if string array was supplied to `-Name` in `Install-PSResource` and `Save-PSResource`
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 576
- Forks
- 114
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 7
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
Steps to reproduce
With Microsoft.PowerShell.PSResourceGet v1.0.6 you can supply -Version when supplying multiple resources with -Name.
That does not make much sense and should error instead of event trying, in my opinion.
Example command:
Install-PSresource -Repository 'PSGallery' -TrustRepository -Scope 'CurrentUser' `
-Name 'Az.Accounts', 'Microsoft.Graph.Authentication' -Version '3.0.5' -Verbose
Expected behavior
ERROR: -Version can only be supplied if -Name is a single value.
Actual behavior
PS > Install-PSresource -Repository 'PSGallery' -TrustRepository -Scope 'CurrentUser' -Name 'Az.Accounts', 'Microsoft.Graph.Authentication' -Version '3.0.5' -Verbose
VERBOSE: All paths to search: 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules'
VERBOSE: All paths to search: 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Scripts'
VERBOSE: Retrieving directories in the path 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules'
VERBOSE: Retrieving directories in the path 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Scripts'
VERBOSE: All paths to search: 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules\Microsoft.PowerToys.Configure'
VERBOSE: The PSGetModuleInfo.xml file found at location: C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules\Microsoft.PowerToys.Configure\0.86.0.0\PSGetModuleInfo.xml cannot be parsed due to TryReadPSGetInfo: Cannot read the PSResourceGet information file with error: Could not find file 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules\Microsoft.PowerToys.Configure\0.86.0.0\PSGetModuleInfo.xml'.
VERBOSE: Attempting to search for packages in 'PSGallery'
VERBOSE: Performing the operation "Install-PSResource" on target "Package to install: 'Az.Accounts', version: '3.0.5'".
VERBOSE: Performing the operation "Install-PSResource" on target "Exit ShouldProcess".
VERBOSE: Installation source path is: 'C:\Users\olav.birkeland\AppData\Local\Temp\a9dc49c9-a34a-4630-b611-f7c93885c5f4\az.accounts\3.0.5'
VERBOSE: Installation destination path is: 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules\Az.Accounts\3.0.5'
VERBOSE: Attempting to move 'C:\Users\olav.birkeland\AppData\Local\Temp\a9dc49c9-a34a-4630-b611-f7c93885c5f4\az.accounts\3.0.5' to 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules\Az.Accounts\3.0.5'
VERBOSE: Successfully installed package 'Az.Accounts' to location 'C:\Users\olav.birkeland\<redacted>\Documents\PowerShell\Modules'
VERBOSE: Attempting to delete 'C:\Users\olav.birkeland\AppData\Local\Temp\a9dc49c9-a34a-4630-b611-f7c93885c5f4'
VERBOSE: Successfully deleted 'C:\Users\olav.birkeland\AppData\Local\Temp\a9dc49c9-a34a-4630-b611-f7c93885c5f4'
VERBOSE: Package with name 'Microsoft.Graph.Authentication', version '3.0.5' could not be found in repository 'PSGallery'.
VERBOSE: Attempting to delete 'C:\Users\olav.birkeland\AppData\Local\Temp\3b2ac088-6a76-4541-85bb-0501bd87b2c1'
VERBOSE: Successfully deleted 'C:\Users\olav.birkeland\AppData\Local\Temp\3b2ac088-6a76-4541-85bb-0501bd87b2c1'
Install-PSResource: Package(s) 'Microsoft.Graph.Authentication' could not be installed from repository 'PSGallery'.
PS >
Error details
No response
Environment data
- Windows 11 24H2
- PowerShell x64 v7.4.6
- Microsoft.PowerShell.PSResourceGet v1.0.6
Visuals
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the commands shown for Install-PSResource and the equivalent Save-PSResource case, then trace their parameter validation. The change is done when supplying multiple -Name values with -Version produces the stated error, while a single -Name value continues to work; add or update coverage where the existing command tests are located.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100