How can I execute a program on a remote machine using powershell?
|
The cool new way to do this is with WinRM. I've seen this demo'd on Windows Server 2008 R2, although there is a download with powershell v2 & WinRM for other windows operating systems. The not so cool (or new) way to do this is to use psexec, which isn't powershell, but I'm sure there's some way to invoke it via powershell-esque syntax. |
|||||||||
|
|
You could also use WMI and remotely start a process. It won't be interactive and you'll have to trust that it will end on its own. This doesn't require anything on the remote computer other than open ports for WMI.
Sample usage:
|
||||
|
|
Interesting enough I used this to run notepad on a remote computer and it didn't appear. I checked the Task manager and the process ID that the call returned was indeed there! Windows stated that this was a security concept and the process would run hidden/ or in the background! |
|||
|
|
|
RE: Nick's answer Yes, PowerShell v2 (with WinRM 2.0) is bundled with Server 2008 R2 and Windows 7. A downlevel version should be available soon for XP, Vista, 2003 and 2008. You always have the option of using WMI also to run remote stuff, but it is must interact with the console, that won't be a viable method. |
|||
|
|
|
it all works really well - but ... I wanna start the application / program in another profile/user. Now it starts as in my credentials which I can't use. I want to start it in another users credentials. I'm domain admin - and I don't have the password on the other user. |
|||
|
|
|
This code helped me execute a bat file remotely, hopefully this helps someone in the future. You'll need to replace the creds and ComputerName vars at the top of this script.
|
|||
|
|