Powershell中的psexec不';不接受加密密码

Powershell中的psexec不';不接受加密密码,powershell,password-encryption,psexec,Powershell,Password Encryption,Psexec,Powershell脚本在远程计算机上执行script.ps1 read-host -assecurestring | convertfrom-securestring | out-file D:\Script\cred.txt $password = get-content D:\Script\cred.txt | convertto-securestring $pwd = "plaintext_password" $j = "remote_computer" $comp = "\\"+$j

Powershell脚本在远程计算机上执行script.ps1

read-host -assecurestring | convertfrom-securestring | out-file D:\Script\cred.txt
$password = get-content D:\Script\cred.txt | convertto-securestring

$pwd = "plaintext_password"
$j = "remote_computer"
$comp = "\\"+$j

$command = "D:\PSTools\PsExec.exe $comp -u Administrator -p $pwd -accepteula powershell.exe c:\share\script.ps1"

Invoke-Expression $command
但是,如果我用$password替换$pwd,即

$command = "D:\PSTools\PsExec.exe $comp -u Administrator -p $password -accepteula powershell.exe c:\share\script.ps1"
我明白了


我多次正确输入密码

这返回的是SecureString,而不是未加密的字符串:

$password = get-content D:\Script\cred.txt | convertto-securestring
当该变量在字符串中使用时,它将扩展为类型名称
System.Security.SecureString
。您可以使用以下脚本将加密密码提取为纯文本:

$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
$str =  [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$str
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
$str =  [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr)
$str