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 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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish