question

phantom2000-5377 avatar image
0 Votes"
phantom2000-5377 asked MotoX80 edited

Run powershell script on a remote computer using PsExec

Hello,

I am using below code to run a powershell script using PsExec. But it does not seem to work. I am using Start-Process cmdlet to run PsExec using Powershell.

Start-Process -FilePath C:\tmp\PSExec.exe -ArgumentList "\\server.fqsn.com Powershell.exe '-ExecutionPolicy Bypass -File C:\tmp\email.ps1'"

Any help on this is greatly appreciated.

Thank you.

windows-server-powershell
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am getting an error saying %1 PSEXECSVC is not a valid win32 application error. I see that PSEXEC creates the PSEXECSVC on the remote computer. But it's 0KB. No matter how many times I run it after deleting the service "sc delete PSEXECSVC" I get the same error. I'm not sure what's wrong.

0 Votes 0 ·

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered MotoX80 edited

Hard to tell what happened. Try this "cleanup" sequence.

 net stop PSEXESVC
 taskkill /im PSEXESVC.exe /f /t
 sc delete PSEXESVC
 del C:\Windows\PSEXESVC.exe

Also; be aware that psexec is not going copy the email.ps1 script from the source pc to the target machine for you. You will need to do that yourself.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.