Skip to content

Explicitly Setting $whatif = $false Prevents Module Installation #1805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
milosbithawk opened this issue Mar 10, 2025 · 4 comments
Open
3 tasks done

Explicitly Setting $whatif = $false Prevents Module Installation #1805

milosbithawk opened this issue Mar 10, 2025 · 4 comments
Assignees
Labels
Issue-Bug Something isn't working

Comments

@milosbithawk
Copy link

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

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

Image
Image

@sdwheeler
Copy link
Contributor

sdwheeler commented Mar 21, 2025

This is the same problem with other cmdlets that was reported in PowerShell/PowerShell#25015. The logic for testing switch parameters is not correct.

@sdwheeler
Copy link
Contributor

The problem is here:

if (_cmdletPassedIn.MyInvocation.BoundParameters.ContainsKey("WhatIf"))

Besides testing for the parameter set or if the parameter exists, it should also test the value of the parameter.

@surfingoldelephant
Copy link

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.

@sdwheeler
Copy link
Contributor

I think the current issue is enough. They need to look at all SwitchParamter instances.

@anamnavi anamnavi self-assigned this Apr 16, 2025
@anamnavi anamnavi added Issue-Bug Something isn't working and removed Needs-Triage labels Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants