Explicitly Setting $whatif = $false Prevents Module Installation
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
When using PowerShell 7.5 with Microsoft.PowerShell.PSResourceGet (version 1.1.1), explicitly setting $whatif to $false prevents the module from being installed Example: $whatif=$false Install-PSResource -Name Microsoft.Entra -WhatIf:$whatif -Scope AllUsers
- PowerShell 5.1 Behavior – Module Installs as Expected Install-Module -Name Microsoft.Entra -WhatIf:$whatif -Scope AllUsers -AllowClobber
Expected behavior
The Module should be installed.
Actual behavior
The module is not getting installed
Error details
No error message generated
Environment data
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
This is the same problem with other cmdlets that was reported in https://github.com/PowerShell/PowerShell/issues/25015. The logic for testing switch parameters is not correct.
The problem is here: https://github.com/PowerShell/PSResourceGet/blob/89ca445d9e50c02607703594c59294aef2c0f416/src/code/InstallHelper.cs#L675
Besides testing for the parameter set or if the parameter exists, it should also test the value of the parameter.
This is also ignored:
Register-PSResourceRepository -PSGallery:$false
I can create a separate issue for this if desired. Or perhaps this current issue can be repurposed to address all instances of the problem in PSResourceGet.
I think the current issue is enough. They need to look at all SwitchParamter instances.