Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell - Get-Credential decode password?

I want to use the Get-Credential cmdlet in my code.

How is is possible to decode the password easily back from the System.Security.SecureString format?

(I must use the password in clear text format at one part in my code)

$credential = Get-Credential $credential.Password | ConvertFrom-SecureString $credential #How to show password in text format? 

My workaround, but I think there is also a normal way

$credCachePS = New-Object System.Net.CredentialCache  $credCachePS.Add("uridummy", "NTLM", $credential)  $credCachePS | select Password 
like image 738
LaPhi Avatar asked Sep 15 '11 15:09

LaPhi


People also ask

How do I get past credentials in PowerShell?

There are a few ways that you can create a credential object. The first way to create a credential object is to use the PowerShell cmdlet Get-Credential . When you run without parameters, it prompts you for a username and password. Or you can call the cmdlet with some optional parameters.

How do I pass credentials in PowerShell without prompt?

$cred = Get-Credential without asking for prompts in powershell - Microsoft Tech Community.

Which cmdlet parameter provide credentials in PowerShell?

The most common use is to run the function or cmdlet as an elevated user account. For example, the cmdlet New-ADUser has a -Credential parameter, which you could provide domain admin credentials in order to create an account in a domain.

How do I make my PSCredential?

Typically, to create a PSCredential object, you'd use the Get-Credential cmdlet. The Get-Credential cmdlet is the most common way that PowerShell receives input to create the PSCredential object like the username and password. The Get-Credential cmdlet works fine and all but it's interactive.


2 Answers

This is what I use ( though this makes it insecure, but I think you understand that):

$credential.GetNetworkCredential().password 
like image 162
manojlds Avatar answered Sep 19 '22 07:09

manojlds


PS > $credential.GetNetworkCredential().username PS > $credential.GetNetworkCredential().password 
like image 24
Shay Levy Avatar answered Sep 21 '22 07:09

Shay Levy