Q. If I have a credential object in PowerShell, how can I extract the account password?

To access the password is actually very simple, assuming the credential is stored in $cred .

John Savill

September 15, 2015

1 Min Read
Q. If I have a credential object in PowerShell, how can I extract the account password?

Q. If I have a credential object in PowerShell, how can I extract the password of the account stored in the credential?
Dept - PowerShell

A. Credentials are created by passing a username and a secure string containing the password. There may be times when you actually need the plain text password back from the credential — for example, if you need to construct the URL for a GRAPH API call to Azure AD. To access the password is actually very simple, assuming the credential is stored in $cred to access the plain text password use:

$cred.GetNetworkCredential().Password

Note the username can also be extracted with $cred.Username.

A more general note: credentials are are very useful to connect to resources and they can even be saved as assets in technologies such as Azure Automation. You can then extract the credentials and use them in runbooks.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like