How to execute a powershell script available in remote machine? How to execute a powershell script available in remote machine? powershell powershell

How to execute a powershell script available in remote machine?


When you write :

invoke-command -computer $MachineName -filepath "C:\hello.ps1"

The script C:\hello.ps1 will be taken from the client computer and brought to the server to be executed. So you've got the error file does not exist because Invoke-Command is looking for the file in the client computer.


I got the same error but I hooked a Remote session in a variable in your code and finally have something that works:

$s = New-PSSession -ComputerName "WTxxxxxL32" -Credential $credentialInvoke-Command -Session $s -Command {D:\ServerDLLDev\RemoteCOMInstall.ps1}

There are a million Invoke-etc solutons but the simplest worked finally for me. Thanks to you.


I had the exact same probe, and solved it with a combination of [WMICLASS] 's create() and Start-Process.

Check my answer here.