windows - Invoking remote command/script with specific credentials -
i attempting invoke remote batch script using powershell.
here sample code:
invoke-command -computername 127.0.0.1 {c:\myfile.bat}
myfile.bat contains this:
echo %username% copy \\10.10.10.10\sample c:\tome
when invoke myfile.bat locally in cmd window, fine. username expected. however, when run invoke-command using powershell, gives me error, while username still correct:
access denied.
here have tried far.
$password = convertto-securestring "mypassword" -asplaintext -force $username = "domain\username" $cred = new-object -typename system.management.automation.pscredential -argumentlist $username, $password invoke-command -computername 127.0.0.1 {myfile.bat} -credential $cred
however, while equates same username, still gives me same error.
i tried create psdrive, , execute command well:
new-psdrive -name x -psprovider filesystem -root \\10.10.10.10\sample invoke-command -computername 127.0.0.1 {myfile.bat} remove-psdrive x
but same error. stumped. without changing batch script, can in powershell make fulfill request?
does work you?
$password='p@ssword'|convertto-securestring -asplaintext -force; $cred=new-object -typename system.management.automation.pscredential('domain\username',$password); invoke-command -computer 127.0.0.1 {c:\myfile.bat} -credential $cred;
or
$password='p@ssword'|convertto-securestring -asplaintext -force; $cred=new-object -typename system.management.automation.pscredential('domain\username',$password); $s = new-pssession -computer "127.0.0.1" -credential $cred; invoke-command -session $s -scriptblock { cmd /c "c:\myfile.bat" }; remove-pssession $s;
also, may test changing domain\username
username
Comments
Post a Comment