我們試圖將用戶密碼作爲安全字符串存儲在註冊表中,但似乎無法找到將其轉換回純文本的方式。這可能與SecureString?Powershell SecureString加密/解密爲純文本不起作用
這是我們正在嘗試使用簡單的測試腳本...
Write-Host "Test Start..."
$PlainPassword = "@SomethingStupid" | ConvertTo-SecureString -AsPlainText -Force
$BSTR = ` [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($PlainPassword)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Write-Host "Password is: " $PlainPassword
Read-Host
這是我們得到的錯誤...
The term ' [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR'
is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\test.ps1:4 char:71
+ $BSTR = ` [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR
<<<< ($PlainPassword)
+ CategoryInfo : ObjectNotFound: (
[System.Runtim...ureStringToBSTR:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Cannot find an overload for "PtrToStringAuto" and the argument count: "1".
At C:\test.ps1:5 char:75
+ $PlainPassword =
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto <<<< ($BSTR)
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
嘗試沒有包裹$ BTSR符合反勾 –
給我一個語法錯誤「意外令牌」的背景下... – devfunkd
好吧,嘗試實際上將明文放在它自己的字符串變量中,就像在我認爲您正在查看的文章中一樣 - http://social.technet.microsoft.com/wiki/contents/articles/4546.working-with-passwords -secure-strings-and-credentials-in-windows-powershell.aspx –