Clear all cached/stored passwords in Windows using the Command Prompt (CMD)

1. List all stored credentials

cmdkey /list

2. Delete all stored credentials

Run this command for each listed target name from step 1:

cmdkey /delete:<target_name>

Example:

cmdkey /delete:TERMSRV/servername

To clear all at once, you can use a for loop in CMD:

for /f "tokens=1,* delims=:" %a in ('cmdkey /list ^| findstr "Target"') do cmdkey /delete:%b

3. Clear mapped network drive credentials (if any)

To remove saved credentials for mapped network drives:

net use * /delete /y

This deletes all active connections and their associated credentials.

PowerShell methods to update credentials, depending on where the old password is being used:


πŸ”§ Option 1: Update Password for a Scheduled Task

If the failed logon is from a scheduled task:

$taskName = "YourTaskName"
$taskPath = "\"
$username = "YOURDOMAIN\Your.Admin"
$password = "NewSecurePassword123!"

$task = Get-ScheduledTask -TaskName $taskName -TaskPath $taskPath
$task.Principal.UserId = $username
Set-ScheduledTask -TaskName $taskName -TaskPath $taskPath -User $username -Password $password

πŸ”§ Option 2: Update Password for a Windows Service

If a Windows service is running under Your.admin:

$serviceName = "YourServiceName"
$username = "YOURDOMAIN\Your.Admin"
$password = "NewSecurePassword123!"

# Set the new credentials for the service
$service = Get-WmiObject -Class Win32_Service -Filter "Name='$serviceName'"
$service.Change($null, $null, $null, $null, $null, $null, $username, $password)
Restart-Service -Name $serviceName

πŸ”§ Option 3: Store Updated Credentials in Windows Credential Manager

If a script or application uses Credential Manager:

$target = "MyApp:Your.Admin"
$username = "YOURDOMAIN\Your.Admin"
$password = "NewSecurePassword123!"

cmdkey /add:$target /user:$username /pass:$password

πŸ›‘ Security Reminder:

  • Avoid hardcoding passwords in plain text inside scripts. Use [SecureString] or a credential vault when possible.
  • If you’re using scripts or apps, check whether they cache credentials elsewhere (e.g., config files, connection strings).

Leave a Reply

Your email address will not be published. Required fields are marked *