Skip to content

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

Description

@milosbithawk

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

Activity

  1. sdwheeler commented on Mar 21, 2025

    @sdwheeler
    Contributor

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

  2. sdwheeler commented on Mar 21, 2025

    @sdwheeler
    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.

  3. surfingoldelephant commented on Mar 26, 2025

    @surfingoldelephant

    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.

  4. sdwheeler commented on Mar 26, 2025

    @sdwheeler
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions