MENU
Have you ever been given an application and instructed to run it on various computers and systems, only to realize that it wasn’t built for multiple hosts? After all, some apps are designed to be executed only locally.
While this problem can be perplexing, many IT professionals understand that they can run an app like this with various deployment tools. These tools copy the app to the necessary computers and execute it. Although this method can solve the problem, it can be overkill.
Fortunately, Microsoft PowerShell provides several ways to invoke applications on remote computers, giving you a quick way to copy the app to a few machines and get it running.
PowerShell offers various ways to execute applications on remote computers. Two methods use Windows Management Implementation (WMI), and a third process uses PowerShell remoting, the preferred method.
The Win32_Process WMI class is one way to run a process on a remote computer. Similar to how you might use PowerShell to manage IIS (a way to host websites on remote computers), you can use PowerShell to run programs on other computers.
Win32_Process is a WMI class with a static method called Create(), which allows you to pass an EXE to it and run it on the remote computer using the WMICLASS-type accelerator.
WMICLASS is a shortcut to enable access to all of the class’s static properties and methods. Because Create() is a static method, you don’t actually have to initiate a Win32_Process object at all. You can simply call the method with the EXE as the first argument, and it will run.
([WMICLASS]”MEMBERSRV1RootCIMV2:Win32_Process”).create(“notepad.exe”)
In this instance, you’re running the Notepad.exe process on the computer MEMBERSRV1. However, this process is not interactive, so you won’t see Notepad.exe pop up on a logged-in console. Remote process execution is best for applications that don’t require interactive input.
The WMICLASS-type accelerator makes running EXEs on remote computers more streamlined and less prone to error.
You can also use the Invoke-WmiMethod cmdlet, which is a less-convoluted process. Invoke-WmiMethod is a more user-friendly way to call static methods such as Create().
Invoke-WmiMethod –ComputerName MEMBERSRV1 -Class win32_process -Name create -ArgumentList “notepad”
This accomplishes the same goal. However, you’re expressing the Win32_Process class and the parameter to Create() — the EXE itself — slightly differently.
The Invoke-WmiMethod cmdlet makes remote application invocation more manageable, which is helpful for more complex operations.
PowerShell remoting will likely be your preferred option for remotely invoking applications. The previous two methods using WMI depended on remote DCOM being enabled on the computer. This may or may not be a problem, but it can sometimes pose a security risk.
You can use PowerShell remoting through the Invoke-Command cmdlet to kick off a process on a remote computer. (You can also use WSMan, a newer, more secure protocol.)
To do this, use a combination of two cmdlets: Invoke-Command to enable you to run a command on the remote computer, and Start-Process to execute the process.
Invoke-Command –ComputerName MEMBERSRV1 –ScriptBlock {Start-Process notepad.exe}
Invoke-Command is a PowerShell cmdlet that allows you to execute code on a remote computer as if it were local. This process has a script block parameter to insert any code to run locally on that remote computer. In this instance, you’re using Start-Process, which runs a specific application.
The Invoke-Command cmdlet does more than remotely launch applications. This versatile scripting tool can also enable you to remotely sync commands with PowerShell.
PowerShell provides numerous ways to invoke processes on remote computers. Start with Invoke-Command/Start-Process to see if that method gives you the results you need. If not, you might need to look into the older methods of using WMI. At least one of these methods will get that process running remotely.
If the Invoke-Command/Start-Process doesn’t produce the desired results, revert to the WMI method.
Using PowerShell to invoke applications on remote computers has three primary benefits:
Mark Fairlie contributed to this article.