PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

`-WhatIf` results in extra, unwanted output and a spurious error

Open mklement0 opened this issue 1 year ago • 0 comments

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

Install-PSResource Microsoft.PowerShell.PSResourceGet -WhatIf

Expected behavior

A what-if message describing what version would be installed only.

Actual behavior

What if: Performing the operation "Install-PSResource" on target "Package to install: 'Microsoft.PowerShell.PSResourceGet', version: '1.0.1'".
What if: Performing the operation "Install-PSResource" on target "Exit ShouldProcess".
Install-PSResource: Package(s) 'Microsoft.PowerShell.PSResourceGet' could not be installed from repository 'PSGallery'.

That is:

  • an extraneous 'What if:' line is printed
  • an error is unexpectedly reported aftewards


### Error details

```console
Exception             : 
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
    Message : Package(s) 'Microsoft.PowerShell.PSResourceGet' could not be installed from repository 'PSGallery'.
    HResult : -2146233088
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
CategoryInfo          : InvalidData: (Microsoft.PowerShel…s.InstallPSResource:InstallPSResource) [Install-PSResource], ResourceNotFoundException
FullyQualifiedErrorId : InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
InvocationInfo        : 
    MyCommand        : Install-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 18
    Line             : Install-PSResource Microsoft.PowerShell.PSResourceGet -WhatIf
    Statement        : Install-PSResource Microsoft.PowerShell.PSResourceGet -WhatIf
    PositionMessage  : At line:1 char:1
                       + Install-PSResource Microsoft.PowerShell.PSResourceGet -WhatIf
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Install-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

PowerShell 7.4.1 on macOS 14.2.1, module version 1.2.5

Visuals

No response

mklement0 avatar Jan 24 '24 15:01 mklement0