2011-09-15 34 views
21

Tôi muốn sử dụng lệnh Get-Credential trong mã của mình.PowerShell - Mật khẩu giải mã nhận-Credential?

Làm cách nào để có thể giải mã mật khẩu dễ dàng trở lại từ định dạng System.Security.SecureString?

(Tôi phải sử dụng mật khẩu ở định dạng văn bản rõ ràng tại một phần trong mã của tôi)

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

workaround của tôi, nhưng tôi nghĩ đó cũng là một cách thông thường

$credCachePS = New-Object System.Net.CredentialCache 
$credCachePS.Add("uridummy", "NTLM", $credential) 
$credCachePS | select Password 

Trả lời

44

Đây là những gì Tôi sử dụng (mặc dù điều này làm cho nó không an toàn, nhưng tôi nghĩ bạn hiểu điều đó):

$credential.GetNetworkCredential().password 
15
PS > $credential.GetNetworkCredential().username 
PS > $credential.GetNetworkCredential().password 
Các vấn đề liên quan