psexec in Powershell doesn't accept encrypted passwords -
powershell script executes script.ps1 on remote_machine
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 however, if replace $pwd $password, i.e.
$command = "d:\pstools\psexec.exe $comp -u administrator -p $password -accepteula powershell.exe c:\share\script.ps1" i get
the user name or password incorrect. i correctly entered in password numerous times
this returning securestring , not unencrypted string:
$password = get-content d:\script\cred.txt | convertto-securestring when variable gets used in string, expands type name system.security.securestring. can use script below extract encrypted password plain text:
$bstr = [system.runtime.interopservices.marshal]::securestringtobstr($password) $str = [system.runtime.interopservices.marshal]::ptrtostringbstr($bstr) [system.runtime.interopservices.marshal]::zerofreebstr($bstr) $str
Comments
Post a Comment