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
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.
$cred = Get-Credential without asking for prompts in powershell - Microsoft Tech Community.
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.
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.
This is what I use ( though this makes it insecure, but I think you understand that):
$credential.GetNetworkCredential().password
PS > $credential.GetNetworkCredential().username PS > $credential.GetNetworkCredential().password
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With