PowerShell - Get-Credential decode password?

2019-04-03 08:38发布

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

2条回答
做个烂人
2楼-- · 2019-04-03 09:03

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

$credential.GetNetworkCredential().password
查看更多
3楼-- · 2019-04-03 09:12
PS > $credential.GetNetworkCredential().username
PS > $credential.GetNetworkCredential().password
查看更多
登录 后发表回答