Repository navigation
Description
Summary
With $WhatIfPreference = $true in a scope the module sees, the runtime harness neither previews a run nor makes it. It skips its own preparation, starts the host anyway, and returns what that host said as the result of the script. None of the commands involved declares SupportsShouldProcess, so they have no -WhatIf of their own; the preference reaches the cmdlets they call (FUN-33).
A global preference of that kind is what a release rehearsal or a deployment script sets when it is started with -WhatIf, and what Build/Publish-Module.ps1 -WhatIf guards its own steps against (MOD-14).
Findings
| Where | What happens under the preference |
|---|---|
Private/Invoke-IslScriptRun.ps1:65, :67 |
New-Item and Copy-Item print "What if" and do nothing, so the run folder and the copy of the script do not exist. The host is started all the same, with -File pointing at the missing copy. |
Private/Invoke-IslProcess.ps1:182, :188, :235, :261 |
The scheduled-task cmdlets of the SYSTEM and -Credential paths support -WhatIf. This path was not run under the preference; if Register-ScheduledTask and Start-ScheduledTask honour it, no task is registered and the run waits out its timeout. |
Public/Invoke-IntuneWin32AppTest.ps1, Public/Test-IntuneDeployedScript.ps1, Public/Export-IntuneAgentDiagnostic.ps1, Public/Export-IntuneFindingSarif.ps1, Private/Get-IslExportReport.ps1 |
Each creates or removes folders and files with New-Item, Copy-Item or Remove-Item as part of its own work (15 calls). Not run under the preference; the same mechanism applies. |
Stop-IslProcessTree is not affected: its two callers pass -WhatIf:$false since #87.
Evidence
On Windows 11, with a detection script that writes present and exits 0, on PowerShell 7.6.10 and on Windows PowerShell 5.1 alike:
| Exit code | StdOut | StdErr | |
|---|---|---|---|
Invoke-IntuneDetectionTest -Path $script |
0 | present |
empty |
the same after $global:WhatIfPreference = $true |
-196608 | the banner of Windows PowerShell | The argument '...\detect.ps1' to the -File parameter does not exist. |
The second call also printed What if: Performing the operation "Create Directory" and What if: Performing the operation "Copy File". Its result object looks like that of a script that failed.
Decision needed
Two readings are possible, and they lead to different changes:
- The preference is not the harness's business. Its file and task operations are bookkeeping for a run the caller asked for, so each of them passes
-WhatIf:$false, asBuild/Publish-Module.ps1does for its staging steps. A run under the preference then behaves like any other run. - A run is a state change that
-WhatIfshould preview. Then the commands that start a script or write a report declareSupportsShouldProcess(FUN-30),-WhatIfsays what would be run and returns nothing, and the internal operations are pinned as above.
Either way the current behaviour, a real launch against a file that was never copied, is wrong.
Proposed change
- Decide between the two readings.
- Pin the internal operations with
-WhatIf:$falsein the files listed above. - Test each harness command with the preference set around the call, and run the scheduled-task path that way on a lab device.
Discovered and written up with Claude Code.
Activity
fadwen commentedon Nov 23, 2026
The decision is made:
-WhatIfpreviews a run. #90 implements it.Two things that the issue left open were measured for it.
The scheduled-task path under a preference. The issue said this path was not run. On a lab device, as
NT AUTHORITY\SYSTEMunder Windows PowerShell 5.1,Invoke-IntunePlatformScriptTest -Context Systemwith$WhatIfPreferenceset in the global scope ended with an error and left oneIntuneScriptLab-*scheduled task registered. The reason is in the cmdlets:-WhatIfRegister-ScheduledTaskStart-ScheduledTaskStop-ScheduledTaskUnregister-ScheduledTaskSo the task was created and started whatever the preference, and only its removal was skipped. That is the same on PowerShell 7.6.10. With #90 nothing runs and no task is left.
The write to the tenant.
Get-IntuneScriptHealthcreates a report export job for the app install counts, a POST that needs a ReadWrite scope.Invoke-MgGraphRequestdoes not consult the preference, so a preview would still have created the job. #90 asks about it withShouldProcess, and about the file of-MarkdownPath; the reads are made and the reports returned.Discovered and written up with Claude Code.
fix(harness): pin -Confirm as well as -WhatIf inside a run