Skip to content

Remove login credentials with command line

1. Introduction

Windows stores information relating to “credentials” in its identity manager.

When a connection problem occurs, it may be useful to delete these stored “credentials”.

It is possible to do this from the command line using the CMDKEY tool and thus provide a shortcut to a .CMD file that can help troubleshoot a user.

2. Delete stored credentials with the command line

To list all the “credentials” stored on a Windows 10 client workstation, all you have to do is use the following command (with the account of the user concerned):

cmdkey /list

To empty all of the stored “credentials” (MS365 connections and other products), the following command can be used:

FOR /F “tokens=1,3 delims= ” %G in (‘cmdkey /list ^| findstr target’) DO cmdkey /delete:%H

To delete only the “credentials” stored for for example OneDrive, just filter on the keyword “onedrive”:

FOR /F “tokens=1,3 delims= ” %G in (‘cmdkey /list ^| findstr /I onedrive’) DO cmdkey /delete:%H

To remove only the “credentials” stored for Teams, just filter on the keyword “teams”:

FOR /F “tokens=1,3 delims= ” %G in (‘cmdkey /list ^| findstr /I teams’) DO cmdkey /delete:%H

Note: It is likely to have multiple Teams credentials because you will have a credential for the user’s account and for their guest accounts from other tenants.