Powershell execute .exe remotely

powershell

$computername = Read-Host "Enter Machine Name - "

Invoke-command -ComputerName $computername -ScriptBlock { & cmd /c 'c:\download\niniteone\niniteone.exe' /select "malwarebytes"}

Wondering if someone could tell me where I've gone wrong with this, it just dies when I run it. I've put this script together by looking at the others here but I can't seem to get it to work. We use ninite pro to update/install some 3rd party apps and I'm trying to setup some powershell scripts to run it on remote computers. Any help would be appreciated 🙂

Update – I added the cmd /c to the script block and now it works great!? I read cmd /c isnt needed with powershell v2? I'm confused… It's working but I'd like to get it right.

Best Answer

How about:

Invoke-command -ComputerName $computername -ScriptBlock { Start-Process -FilePath "c:\download\niniteone\niniteone.exe" -ArgumentList "/select `"malwarebytes`""}