31

我想在我的代码中使用 Get-Credential cmdlet。

如何从 System.Security.SecureString 格式轻松解码密码?

(我必须在我的代码的一部分使用明文格式的密码)

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

我的解决方法,但我认为也有正常的方法

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

2 回答 2

64

这就是我使用的(虽然这使得它不安全,但我想你明白这一点):

$credential.GetNetworkCredential().password
于 2011-09-15T15:15:21.803 回答
18
PS > $credential.GetNetworkCredential().username
PS > $credential.GetNetworkCredential().password
于 2011-09-15T15:16:20.543 回答