2014-09-09 3 views
2

Powershell скрипт выполняет script.ps1 на remote_machinePsExec в Powershell не принимает зашифрованные пароли

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 

Однако, если я заменю $ 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. 

Я правильно ввел пароль несколько раз

ответ

3

Это возвращает 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 
Смежные вопросы