Add Test-ScheduledTaskHealth.ps1 offline diagnostic with -Repair #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/task-scheduler-health-diagnostic"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What does this PR do?
Adds a fourth tool,
Test-ScheduledTaskHealth.ps1, that diagnoses (and optionally repairs) astalled or hung Windows Task Scheduler.
When the Task Scheduler service stalls enumerating tasks, everything that goes through the
service hangs too:
taskschd.msc,schtasks.exe, and theScheduledTaskscmdlets(
Get-ScheduledTask/Get-ScheduledTaskInfo). The usual cause is a single damaged ororphaned task definition.
This script avoids the service entirely and reconciles three sources that the service expects
to agree:
%SystemRoot%\System32\Tasks,TaskCache\Treeregistry entries, andTaskCache\Tasks\{GUID}registry subkeys.It reports:
OrphanTreeEntry,OrphanTaskEntry,MissingXmlFile,OrphanXmlFile,EmptyXmlFile,MalformedXml,UnresolvablePrincipal(opt-in), andReadError.With
-Repairit backs up each item (a native.regexport of the registry key plus a copyof the XML file to
-BackupPath) and then removes it, gated bySupportsShouldProcessso-WhatIf/-Confirmwork. The registry backup uses the .NET registry API rather thanreg.exe, so it works on hosts where theDisableRegistryToolspolicy blocksreg.exe.Backup precedes deletion, so a failed backup aborts the removal and no data is lost.
Fixes #
How was this tested?
every finding category. Verified detection,
-Repair -WhatIf(no changes), and a real-Repairrun: backups written, damaged/orphaned entries removed, the healthy task leftintact. Confirmed the native
.regexport works whereDisableRegistryToolsblocksreg.exe, and that a failed registry backup aborts deletion.Checklist