4

I am trying to call a batch file located in local machine executing the below PowerShell command from remote computer.

Invoke-Command -ComputerName XXXXXX -ScriptBlock {
  Start-Process "c:\installagent.bat"
} -Credential abc\XXX

It's not giving any error but nothing happened on the remote computer.

If I run the batch file from local machine, it's working fine.

1 Answer 1

4

You can't run a local file on a remote host like that. If the account abc\XXX has admin privileges on your local computer (and access to the administrative shares is enabled) you could try this:

Invoke-Command -ComputerName XXXXXX -ScriptBlock {
  param($myhost)
  Start-Process "\\$myhost\c$\installagent.bat"
} -ArgumentList $env:COMPUTERNAME -Credential abc\XXX

Otherwise you'll have to copy the script to the remote host first:

Copy-Item 'C:\installagent.bat' '\\XXXXXX\C$'

Invoke-Command -ComputerName XXXXXX -ScriptBlock {
  Start-Process "c:\installagent.bat"
} -Credential abc\XXX

Also, I'd recommend using the call operator (&) instead of Start-Process for running the batch file:

Invoke-Command -ComputerName XXXXXX -ScriptBlock {
  & "c:\installagent.bat"
} -Credential abc\XXX

That way Invoke-Command should return the output of the batch file, giving you a better idea of what's going on.

Or, you could simply use psexec:

C:\> psexec \\XXXXXX -u abc\XXX -c installagent.bat
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.