Fix HKU PSDrive creation failing under -WhatIf in EOMT#2540
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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:$falseto theNew-PSDrivecall creating theHKU:drive inInstall-IISUrlRewriteModule.ps1.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lusassl-msft
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running
EOMT.ps1 -CVE 'CVE-2026-42897' -WhatIf, theNew-PSDrivecall for HKU is skipped becauseNew-PSDrivesupportsShouldProcessand respects the inheritedFalse. The subsequentGet-ChildItem HKU:then fails with:Root Cause
EOMT.ps1declaresSupportsShouldProcessand when called with-WhatIf,Falsepropagates to all child calls.New-PSDrive(which natively supportsShouldProcess) honors this and skips drive creation, causing the downstreamGet-ChildItem HKU:to fail.The bug is only observable when
-WhatIfis the first invocation in a fresh PowerShell session. If the script was previously run without-WhatIf, theHKU:PSDrive persists in the session, masking the issue.Fix
Added
-WhatIf:$falseto theNew-PSDrivecall inGet-InstalledSoftwareVersion. Creating a read-only PSDrive alias is not a system-changing operation and should always execute regardless ofWhatIfPreference.