One way would be with PsExec:
psexec \\server_ip "path_to_where_the_file_should_go/file.exe"
Other methods include remote Powershell, telnet, SSH.
Answer from simlev on Stack ExchangeDid you try using the -ArgumentList parameter:
invoke-command -ComputerName studio -ScriptBlock { param ( $myarg ) ping.exe $myarg } -ArgumentList localhost
http://technet.microsoft.com/en-us/library/dd347578.aspx
An example of invoking a program that is not in the path and has a space in it's folder path:
invoke-command -ComputerName Computer1 -ScriptBlock { param ($myarg) & 'C:\Program Files\program.exe' -something $myarg } -ArgumentList "myArgValue"
If the value of the argument is static you can just provide it in the script block like this:
invoke-command -ComputerName Computer1 -ScriptBlock { & 'C:\Program Files\program.exe' -something "myArgValue" }
Are you trying to pass the command line arguments to the program AS you launch it? I am working on something right now that does exactly this, and it was a lot simpler than I thought. If I go into the command line, and type
C:\folder\app.exe/xC:\folder\file.txt
then my application launches, and creates a file in the specified directory with the specified name.
I wanted to do this through a Powershell script on a remote machine, and figured out that all I needed to do was put
$s = New-PSSession -computername NAME -credential LOGIN
Invoke-Command -session $s -scriptblock {C:\folder\app.exe /xC:\folder\file.txt}
Remove-PSSession $s
(I have a bunch more similar commands inside the session, this is just the minimum it requires to run) notice the space between the executable, and the command line arguments. It works for me, but I am not sure exactly how your application works, or if that is even how you pass arguments to it.
*I can also have my application push the file back to my own local computer by changing the script-block to
C:\folder\app.exe /x"\\LocalPC\DATA (C)\localfolder\localfile.txt"
You need the quotes if your file-path has a space in it.
EDIT: actually, this brought up some silly problems with Powershell launching the application as a service or something, so I did some searching, and figured out that you can call CMD to execute commands for you on the remote computer. This way, the command is carried out EXACTLY as if you had just typed it into a CMD window on the remote machine. Put the command in the scriptblock into double quotes, and then put a cmd.exe /C before it. like this:
cmd.exe /C "C:\folder\app.exe/xC:\folder\file.txt"
this solved all of the problems that I have been having recently.
EDIT EDIT: Had more problems, and found a much better way to do it.
start-process -filepath C:\folder\app.exe -argumentlist "/xC:\folder\file.txt"
and this doesn't hang up your terminal window waiting for the remote process to end. Just make sure you have a way to terminate the process if it doesn't do that on it's own. (mine doesn't, required the coding of another argument)
run a remote EXE with argument, from a user share but have the command run on the server that the share resides on, not local machine.
c# - I want to run .exe as a webserver on a remote host - Stack Overflow
command prompt - How to run exe on remote PC using psexec - Stack Overflow
run a remote EXE with argument, from a user share but have the command run on the server that the share resides on, not local machine.
Videos
How about this?
$Directory = "d:\rootfilepath"
# this is not really the preferred way
Invoke-Command -Computer SERVERNAME -ScriptBlock {& "D:\incomingdatafiles\datafileloader\datafileloader\callDatafileUploader1.ps1 $using:Directory"}
# This is safer (and preferred)
Invoke-Command -Computer SERVERNAME -ScriptBlock {Start-Process -NoNewWindow -FilePath "D:\incomingdatafiles\datafileloader\datafileloader\callDatafileUploader1.ps1" -ArgumentList $using:Directory}
Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
( Does the latest problem idea from RichMatheisen-8856 help you? )
My network admins would use Powershell for this. Not sure if you are restricted to only CMD.
invoke-command -computername SYSDES208 -scriptblock { D:\TestFile.exe }
If you are using a domain account or have the exact same account on the remote machine you shouldn't need to enter credentials as powershell will use the cred of the local user.
you need to add credential as well to run that exe.(Pass the credential in PSEXEC command) Make sure that your account also has the write and modify permission at the location at which file is being generated
PSExec has the capability of running against a list of computers:
Usage: psexec [\computer[,computer2[,…] | @file][-u user [-p psswd]][-n s][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-][-a n,n,… ] cmd [arguments]
@file Directs PsExec to run the command on each computer listed in the text file specified.
I am trying to create either a VBS or CMD script that will allow me, to run an executable that is already located in the same location on every single machine we have, there is a folder to the .exe that is the same location on each machine and instead of walking around to 300 machines, i’d like to just have it run from my desk.
Group Policy is out of the question because not all machines are defined in AD.
I wanted to use the script reference a list of IP’s.
Is that possible or anyone have something similar i could use?
Thanks!
Invoke-Command is the cmdlet to use, I think. Have you tried that:
Invoke-Command -ComputerName Blah -ScriptBlock { c:\folder\file.exe }
There are some caveats.
In the actual path, are there spaces? If so you need to use Invoke-expression or Start-Process inside of the script block.
Does the .exe need to have permissions to a share on another computer? If so then you are running into a double hop authentication issue.
If you continue to have trouble, please post back the code you ran and the errors you got, and as much detail as possible. Post the real paths, too.
I’ve got the .exe copied locally to a remote computer but I can’t get the command correct to trigger it to run on the remote computer. The .exe is located on the remote computer at c:\folder\file.exe. Any help is appreciated.
You created a pssession to the remote computer but didn't use it. Your Start-Process was run on the computer hosting the script. You need to use Enter-PSSession since it:
Starts an interactive session with a remote computer.
Once you are in a session then you do not need to run the WMI commands remotely. You can run them like you were running on the server directly. Borrowing from the example on MSDN
The first command uses the Enter-PSSession cmdlet to start an interactive session with Server01, a remote computer. When the session starts, the command prompt changes to include the computer name.
PS C:\> Enter-PSSession -Computer Server01 [Server01]: PS C:\>The second command gets the Windows PowerShell process and redirects the output to the Process.txt file. The command is submitted to the remote computer, and the file is saved on the remote computer.
[Server01]: PS C:\> Get-Process Powershell > C:\ps-test\Process.txt
Don't forget to call Exit-PSSession when you are done.
Invoke-Command
If you didn't want to use pssessions then you could also you Invoke-Command on the remote machine as well. You already are trying to do this with your last lines of code.
Invoke-Command -ComputerName $computer -ScriptBlock {Start-Process "bagel.exe"}
If you do go down this path be aware of scoping issues and look up how to pass arguments to the scriptblock.
I am not sure why yours is not working. Perhaps you have some errors being suppressed? I would try something simpler for testing. Is your application GUI based? It might not work when run like this. Try something like ipconfig and see what the results are.
I would also consider a while loop with a timeout condition while you are waiting for the process to terminate/start on the remote machine. That was you can account for failures better instead of assuming that 10 seconds is enough.
I think you've a problem with your local/remote execution.
(Get-WmiObject win32_process -ComputerName $computer -Credential $mycreds | ?{ $_.ProcessName -match "Workbench3.helper" }).Terminate()
Above line returns all processes from the remote computer to your local computer. Than you're fitering the returned process-objects on your LOCAL machine, and call Terminate() on your LOCAL machine. I would suggest you use the following line instead:
Invoke-command -session $pers -ScriptBlock { (Get-WmiObject win32_process -ComputerName $computer -Credential $mycreds | ?{ $_.ProcessName -like"*Workbench3.helper*" }).Terminate()}
This should kill the Workbench3 process(es). I used the like operator to make filtering less strict.
After that, you can reuse the session stored in $pers to start the process again.
Invoke-command -session $pers -scriptblock {Start-Process -filepath "C:\Program Files (x86)\Company Security\Workbench3 Helper\WorkBench3.Helper.exe" -Wait
}
I additionally used the -Waitswitch. The switch forces Start-Process to wait for the programm to be started (and return afterwards).
When doing remote operations I would always suggest to perform these operations via Invoke-Commandand not via the -ComputerName parameters of the several commands. Invoke-Command uses WS-MAN via HTTP(S), while the remote-implemenation of commands offering the -ComputerNameparameter differ in implementation from cmdlet to cmdlet. This advantage of invoke-commandmakes it easier to configure e.g. firewalls.
Hope that helps.
I think you're looking for PsExec
This is what you'd do to execute a CLI program on a remote computer using PsExec:
psexec \\REMOTECOMPUTER "path_to_program_executable"
You can learn more about PsExec and its various options along with some examples here
On more option is the built in winrs
winrs.exe -r:<RemoteComputerName> <TheCommandToRun>
winrs.exe -r:MyRemoteServer ipconfig
winrs vs. psexec
advantages winrs
- Built in, no download needed
- Faster and more reliable than psexec
advantages psexec
- Works with IP (winrs needs the computername (NetBIOS name) of the machine)
- Can run processes in system-context
Hi folks!
I'm trying to run an .exe to remove Adobe from numerous PC's (using the Adobe Creative Cloud Cleaner Tool) and it has been suggested by others that I could run a remote command to do this. I'd like to run this .exe with the xml argument from my local machine, using a user account which has local admin rights on all the other PCs.
Invoke-Command -ComputerName PCNAME-23, PCNAME-24 -FilePath C:\AdobeCreativeCloudCleanerTool.exe -ArgumentList "--cleanupXML=cleanup.xml"
I got as far to write the above, but Invoke-Command only seems to want to use .ps1 files, rather than .exe's. Is there any slight adjustments that could solve this for me? I'm a bit of a newbie, so any help would be massively appreciated.
I want all windows computers connected to the same Domain to want to get the ".exe" file and run it without physically visiting each machine. So I need a central way of distributing the .exe file and sending a command to run it.
How should i do this?
