Report scheduled tasks running under stale accounts
Documentation: Microsoft Learn
The task inventory is read first, then each configured principal is translated to a SID.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Illustrative unresolved principal. A failed name-to-SID translation can also indicate lookup or connectivity problems; it does not prove the account was deleted. Note: tasks running as built-in principals (SYSTEM, LOCAL SERVICE, NETWORK SERVICE without the NT AUTHORITY\ prefix, or raw SIDs) will also fail translation — exclude NT AUTHORITY\* and well-known SIDs before treating a result as stale.
TaskPath : \ TaskName : NightlyReport RunAs : CORP\retired-reporting LastRunTime : 2026-10-01 22:00:00 LastTaskResult : 2147943726
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Get-ScheduledTask | Where-Object { $_.Principal.UserId } | ForEach-Object {
$user = $_.Principal.UserId
$exists = $true
try { [void] ([System.Security.Principal.NTAccount] $user).Translate([System.Security.Principal.SecurityIdentifier]) }
catch { $exists = $false }
if (-not $exists) {
$info = $_ | Get-ScheduledTaskInfo
[pscustomobject]@{ TaskPath= $_.TaskPath;TaskName= $_.TaskName;RunAs= $user;LastRunTime= $info.LastRunTime;LastTaskResult= $info.LastTaskResult }
} }- Stage 1Get-ScheduledTask
Positional values or no named parameters - Stage 2Where-Object
Positional values or no named parameters - Stage 3ForEach-Object
Positional values or no named parameters
How it works
The task inventory is read first, then each configured principal is translated to a SID. A failed translation marks an account reference that Windows cannot currently resolve. Get-ScheduledTaskInfo adds run evidence without modifying the task.
Adapting it
For domain service accounts, combine this with an Active Directory status check so disabled-but-resolvable accounts are also reported.