更新时间:2021-12-04 23:15:38
您很接近,但是您传递给SecureStringToBSTR
的参数必须为SecureString
.您似乎正在传递ConvertFrom-SecureString
的结果,该结果是加密的标准字符串.因此,在传递给SecureStringToBSTR
之前,先对此调用ConvertTo-SecureString
.
You are close, but the parameter you pass to SecureStringToBSTR
must be a SecureString
. You appear to be passing the result of ConvertFrom-SecureString
, which is an encrypted standard string. So call ConvertTo-SecureString
on this before passing to SecureStringToBSTR
.
$SecurePassword = ConvertTo-SecureString $PlainPassword -AsPlainText -Force
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)