gpt4 book ai didi

powershell - Powershell中的psexec不接受加密的密码

转载 作者:行者123 更新时间:2023-12-02 23:28:28 26 4
gpt4 key购买 nike

Powershell脚本在remote_machine上执行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"

我懂了
The user name or password is incorrect.

我多次正确输入密码

最佳答案

这将返回一个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

关于powershell - Powershell中的psexec不接受加密的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25750703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com