Skip to content

Fix HKU PSDrive creation failing under -WhatIf in EOMT#2540

Merged
dpaulson45 merged 1 commit into
mainfrom
dpaul-EOMTFix
May 19, 2026
Merged

Fix HKU PSDrive creation failing under -WhatIf in EOMT#2540
dpaulson45 merged 1 commit into
mainfrom
dpaul-EOMTFix

Conversation

@dpaulson45
Copy link
Copy Markdown
Member

Problem

When running EOMT.ps1 -CVE 'CVE-2026-42897' -WhatIf, the New-PSDrive call for HKU is skipped because New-PSDrive supports ShouldProcess and respects the inherited False. The subsequent Get-ChildItem HKU: then fails with:

Get-ChildItem : Cannot find drive. A drive with the name 'HKU' does not exist.

Root Cause

EOMT.ps1 declares SupportsShouldProcess and when called with -WhatIf, False propagates to all child calls. New-PSDrive (which natively supports ShouldProcess) honors this and skips drive creation, causing the downstream Get-ChildItem HKU: to fail.

The bug is only observable when -WhatIf is the first invocation in a fresh PowerShell session. If the script was previously run without -WhatIf, the HKU: PSDrive persists in the session, masking the issue.

Fix

Added -WhatIf:$false to the New-PSDrive call in Get-InstalledSoftwareVersion. Creating a read-only PSDrive alias is not a system-changing operation and should always execute regardless of WhatIfPreference.

New-PSDrive supports ShouldProcess, so when EOMT.ps1 is run with
-WhatIf the drive creation is skipped and Get-ChildItem HKU: fails.
Adding -WhatIf:$false ensures the read-only PSDrive is always created.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 15, 2026 20:10
@dpaulson45 dpaulson45 requested a review from a team as a code owner May 15, 2026 20:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug in EOMT.ps1 where running with -WhatIf would cause New-PSDrive to be skipped (since it natively supports ShouldProcess), making the subsequent Get-ChildItem HKU: fail. Adds -WhatIf:$false to the New-PSDrive call so the read-only drive alias is always created.

Changes:

  • Add -WhatIf:$false to the New-PSDrive call creating the HKU: drive in Install-IISUrlRewriteModule.ps1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dpaulson45 dpaulson45 merged commit 2685c4f into main May 19, 2026
11 checks passed
@dpaulson45 dpaulson45 deleted the dpaul-EOMTFix branch May 19, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants