Our Thinking / Field Notes / The Fix

TROUBLESHOOTING / WINDOWS TASK SCHEDULER AND AUTOMATION CREDENTIALS

Scheduled Task Failing After a Password Change: How to Diagnose It

A Windows scheduled task that stops after a password change is usually still holding the old one. Here is how to confirm that, rule out a lockout first, update the stored credential once and check the job really runs.

Start here

Don't retype the password yet. First read the task's last result and run-as account, then check that account is not locked, disabled or expired. A task saved with "Run whether user is logged on or not" keeps the old password until someone updates it, so once the account is healthy, re-enter the new password once, run the task and look for a last result of 0.

What this covers and what to do first

This is for a script run by Windows Task Scheduler under a named account, where the account's password was changed or rotated and the job has gone quiet. That is the most common setup and the one where Windows keeps its own copy of the password. If your job is cron, a cloud runbook or an application secret, the last sections point you in the right direction without pretending one recipe fits all of them.

The safest first move is to look, not fix. A scheduled job that fails on a stale password does so on every run, and each failed logon can count towards the account's lockout threshold. Retyping passwords into several tasks before you know the account is healthy is how a quiet failure becomes a locked-out account and a much louder one.

You will typically see one or more of these:

  • The task's Last Run Result shows a logon failure, such as 0x8007052E ("Logon failure: unknown user name or bad password"), or the task never appears to start.
  • The same script runs fine when you launch it by hand under your own account.
  • It started failing at, or soon after, the moment the password was changed or expired.
  • The account itself is suddenly locked, or keeps relocking.

Why a password change breaks a task nothing else touched

When you save a task with "Run whether user is logged on or not", Windows stores the account's password with the task so it can sign in unattended. Microsoft's schtasks reference is plain about the consequence: updating the saved password is required whenever the account's password expires or changes, and if the saved password is no longer valid the task doesn't run. Task Scheduler does not notice the rotation and quietly adapt. It keeps trying the old password with admirable loyalty.

The stored password is only one of three places an old credential can hide, and it pays to know them before you start:

  • The task itself: the saved run-as password. This is what the steps below fix.
  • The script or something it reads: an embedded password, a saved credential file, a connection string, a mapped drive. The task can start perfectly and the script can still fail further in.
  • Other things using the same account: a second task, a service, a colleague's session. They fail too, and together they are the usual reason a lockout keeps coming back.
  • Windows records an unattended task sign-in as a batch logon. In the Security log that appears as a failed logon (event 4625) with logon type 4, so that is the signature to look for in a moment.
  • One thing to settle before any fix: why was the password changed? If it was rotated because someone suspected the credential had leaked, the NCSC's advice is to change passwords when compromise is known or suspected, so the old password must stay dead. Fix the task to use the new one; never restore the old one to make the job work.

Read what Windows recorded (nothing here changes anything)

Run these in PowerShell as an administrator on the computer that hosts the task. They only read information. Replace YOUR_TASK_NAME and YOUR_ACCOUNT_NAME with your own values; if the task sits in a folder in Task Scheduler, you can find its exact name in the first command's output.

  1. Find out which account the task runs as and how it signs in. A logon type of Password means Windows holds a saved password for it, which is the case this article is about.
    powershell
    Get-ScheduledTask -TaskName 'YOUR_TASK_NAME' | Select-Object TaskName, TaskPath, State, @{Name='RunAs';Expression={$_.Principal.UserId}}, @{Name='LogonType';Expression={$_.Principal.LogonType}}
  2. Read the last result. 0 means the last run completed normally. 0x8007052E is the Windows logon-failure error and fits a stale or wrong password. Any other value is a different problem and the "If it still fails" section is the better place to start.
    powershell
    Get-ScheduledTaskInfo -TaskName 'YOUR_TASK_NAME' | Select-Object LastRunTime, NextRunTime, NumberOfMissedRuns, @{Name='LastResultHex';Expression={'0x{0:X8}' -f $_.LastTaskResult}}
  3. Read the Task Scheduler event log for the last few days. Event 101 records that Task Scheduler could not start the task for a user, with an error value attached, and event 104 is documented as a logon failure. If the command reports that no events were found, task history may be switched off: in Task Scheduler, choose Enable All Tasks History in the Actions pane (administrator rights; it applies to all tasks and only records from that point), then run the task once to generate an entry.
    powershell
    Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-TaskScheduler/Operational'; Id=101,104; StartTime=(Get-Date).AddDays(-3)} | Select-Object TimeCreated, Id, Message | Format-List
  4. List every task on this computer that runs as the same account. Each one holds its own saved password and will need the same treatment, so you want the full list before you change anything.
    powershell
    Get-ScheduledTask | Where-Object { $_.Principal.UserId -like '*YOUR_ACCOUNT_NAME' } | Select-Object TaskPath, TaskName, State

Check the account is healthy before you re-enter anything

Every wrong password is a failed logon, and a task that runs every few minutes can rack up a bad-password count quickly. If the account is already locked, disabled or expired, a new password in the task will not help and further attempts make the lockout worse. These checks are read-only.

Failed logons are only recorded if logon-failure auditing is switched on for the computer. The Security log lists the reason for each failure in its Status and Sub Status fields. The ones that matter here, from Microsoft's reference for event 4625:

  • 0xC000006A: misspelled or bad password. This is the stale-password signature, especially with logon type 4.
  • 0xC0000234: the account is locked out. Stop and find the source before anyone re-enters a password.
  • 0xC0000072: the account was disabled by an administrator.
  • 0xC0000193: the account has expired.
  • 0xC000015B: the account has not been granted the requested logon type on this computer. That is a rights problem, not a password one.
  • 0xC000006F and 0xC0000070: logon outside permitted hours, or from a workstation the account is not allowed to use.
  1. For a domain account, check its state. This needs the Active Directory PowerShell module (part of the Remote Server Administration Tools) and permission to read user objects. The values come from whichever domain controller answers, so treat a zero count as encouraging rather than proof.
    powershell
    Get-ADUser -Identity 'YOUR_ACCOUNT_NAME' -Properties LockedOut, BadLogonCount, LastBadPasswordAttempt, PasswordLastSet, PasswordExpired | Select-Object Enabled, LockedOut, BadLogonCount, LastBadPasswordAttempt, PasswordLastSet, PasswordExpired
  2. For a local account on this computer, use this instead. It shows whether the account is enabled and when its password was last set and when it expires.
    powershell
    Get-LocalUser -Name 'YOUR_ACCOUNT_NAME' | Select-Object Name, Enabled, PasswordLastSet, PasswordExpires
  3. Read recent failed logons for the account from the Security log (administrator rights needed). Look at Account Name, Logon Type, Failure Reason, Status and Sub Status. Failures with logon type 4 and a bad-password status at the times the task should have run confirm the stored password is the culprit. A message that says no events were found means either nothing failed or the failures were not audited.
    powershell
    Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625; StartTime=(Get-Date).AddDays(-1)} | Where-Object { $_.Message -like '*YOUR_ACCOUNT_NAME*' } | Select-Object -First 10 | Format-List TimeCreated, Message
  4. Decide from what you found. Locked out: hand over to whoever runs Active Directory. The lockout event 4740 on the domain controller names a Caller Computer Name, which is your starting point for finding who is still using the old password. Disabled or expired: that is a decision for the account's owner. Unlocked, enabled, and failing with a bad password: carry on to the next section.

Re-enter the password once, then prove the job works

This changes the saved credential for one task and then runs that task for real, so do it on one task first and at a time when the job running now will not cause trouble (a backup, an import or a clean-up all do something). You need local administrator rights on the computer and the account's current password. Type it carefully: one deliberate attempt is the plan, not a loop of guesses.

The password itself needs no rollback, since the old one is meant to stay dead. The export below keeps a copy of the task's settings so you can compare or rebuild them if the wrong thing gets changed. It does not contain the saved password, but it does show the account name, paths and arguments, so keep it in a folder only administrators can read.

  1. Export the task definition first. Choose a folder that already exists.
    powershell
    Export-ScheduledTask -TaskName 'YOUR_TASK_NAME' | Out-File -FilePath 'C:\Temp\YOUR_TASK_NAME-before-change.xml'
  2. Update the saved password. Run this from an elevated Command Prompt or PowerShell. Leaving the password off the command line makes schtasks ask for it with the typing hidden, which keeps it out of your command history. If the task is in a folder, give the full path in the task name, for example \YOUR_FOLDER\YOUR_TASK_NAME. The Task Scheduler window works as well: open the task's properties, go to the General tab, and save the task with the account's new password when prompted.
    cmd
    schtasks /change /tn "YOUR_TASK_NAME" /ru "YOUR_DOMAIN\YOUR_ACCOUNT_NAME"
  3. Run the task now. This starts the actual job. Give it a moment to finish; how long depends entirely on what the script does.
    powershell
    Start-ScheduledTask -TaskName 'YOUR_TASK_NAME'
  4. Read the result again. LastRunTime should be the time you just ran it and the last result should be 0. A 0 only tells you the script finished with exit code zero, so also check what the job should have produced (its log, the file it writes, the message it sends), because a script that swallows its own errors can still report success.
    powershell
    Get-ScheduledTaskInfo -TaskName 'YOUR_TASK_NAME' | Select-Object LastRunTime, @{Name='LastResultHex';Expression={'0x{0:X8}' -f $_.LastTaskResult}}
  5. Repeat for each other task you listed earlier that uses the same account, one at a time, and check the account is still unlocked between them.

If it still fails

Match what you see to the nearest of these.

  • The same logon failure again: the password was mistyped or the account name is not written the way the domain or computer knows it. Check the account state again before a second attempt, because the first one may already have counted.
  • A 4625 with logon type 4 and status 0xC000015B: the account no longer has permission to run as a batch job. Microsoft states that tasks using a saved password only launch if the account has the Log on as a batch job right, which administrators and Backup Operators hold by default. Ask whoever owns the user-rights policy to grant it. Adding the account to Administrators to make the error go away is the wrong trade.
  • "A specified logon session does not exist" when saving the task: Microsoft documents a security setting, Network access: Do not allow storage of passwords and credentials for network authentication, as a cause on older Windows releases, because it stops Windows keeping the password at all. It is a deliberate control, so raise it with whoever owns the policy rather than switching it off.
  • The task now returns 0 or starts, but the script fails reaching a file share, database or web service: the saved password is fine and the old one is hiding somewhere else, such as an embedded credential, a saved credential file or a mapped drive. A task set to run whether the user is logged on or not has no interactive desktop, and Microsoft's guidance is to use UNC paths rather than mapped drives for it.
  • It worked for a while after the change and then failed again: treat that as a separate question, not as proof of any one cause. Line up the time of the first failure with the 4625 and lockout events, and look for another system or person still using the old password.
  • The account relocks within minutes: something else is still sending the old password. The Caller Computer Name in event 4740 can be blank or misleading, in which case the authentication events logged just before it (4776 for NTLM, 4771 for Kerberos) usually help. This is a job for your domain administrator.

If your job is not a Windows scheduled task

The logic carries over even when the tools do not: find out where the credential actually lives, then check whether the thing it signs in to is rejecting it. The detail differs.

On Linux with cron, the job has no stored password of its own. Whatever the script reads, whether a file, an environment variable or a keyring, is where the old credential sits, and the authentication log of the system it connects to is where the rejection shows up.

For anything that signs in to Microsoft 365 or Azure as an application, the likelier culprit is an expired client secret, not a rotated user password. In the Microsoft Entra admin centre, open App registrations, choose the application, then Certificates & secrets and Client secrets to see expiry dates. Secret lifetimes are capped at 24 months, and Microsoft recommends under 12. Microsoft also recommends certificates or federated credentials over secrets for production, which removes this particular cliff edge.

Making the next rotation uneventful

Keep this short and practical: the aim is that the next rotation does not need a diagnosis. Write down which tasks and scripts use which account, which is exactly the list you built above. Where the job runs on a domain-joined server, a group managed service account (gMSA) lets Active Directory manage the password and hand it to the computer, so there is no human-typed password to go stale. It needs a domain and some one-off setup, so treat it as a planned change for the account owner, not something to improvise during an outage.

Technical terms explained
bad-password count
The number of recent failed sign-ins recorded against an account. Reaching the lockout threshold set by policy locks the account.
gMSA
Group managed service account: an Active Directory account whose password is generated and rotated automatically by the domain, so nobody types or stores it.
Log on as a batch job
A Windows user right that an account needs before Task Scheduler can run a task with a saved password under it. Administrators and Backup Operators have it by default.
logon type
A number in a Windows logon event that says how the sign-in happened. Type 4 is a batch logon, used when a scheduled task runs under an account without anyone present.

Sources and further reading

KEEP THE CONVERSATION GOING

Automation that survives a password change

If scripts across your servers rely on shared accounts and nobody is quite sure which, we can help you map them and move them to credentials that don't break at rotation.

Talk to us