Menu
Business.com aims to help business owners make informed decisions to support and grow their companies. We research and recommend products and services suitable for various business types, investing thousands of hours each year in this process.
As a business, we need to generate revenue to sustain our content. We have financial relationships with some companies we cover, earning commissions when readers purchase from our partners or share information about their needs. These relationships do not dictate our advice and recommendations. Our editorial team independently evaluates and recommends products and services based on their research and expertise. Learn more about our process and partners here.
PowerShell offers several ways to invoke applications on remote computers.
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 Instrumentation (WMI), and a third process uses PowerShell remoting, the preferred method.
“PowerShell remoting lets you manage multiple machines from one console, making your work much more efficient,” said Ismail Durgut, an experienced freelance programmer. “You can run scripts and commands on remote systems, which streamlines tasks and cuts down the need for physical access. Plus, it keeps your systems secure by using encrypted communication channels.”
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(). This method 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]”\MEMBERSRV1\root\cimv2: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 WMI Create() method works well for creating new instances of WMI classes, but it can feel limited for more complex tasks,” offered Durgut. “Invoke-WmiMethod gives you a more flexible and user-friendly way to execute methods on WMI objects. It also handles errors better, which makes your work easier.”
You can also use the Invoke-WmiMethod cmdlet, which is a less complicated process and 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.
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.
“WMI methods feel clunky compared to modern PowerShell remoting,” said web developer Vincent Schmalbach. “While Create() and Invoke-WmiMethod both work, they’re basically legacy tools at this point. Invoke-WmiMethod is slightly easier to use since it has PowerShell-style syntax, but both are slower and more limited than just using Enter-PSSession.”
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.
Durgut shared with business.com his steps for setting up PowerShell remoting securely and effectively: “Start by enabling remoting with Enable-PSRemoting. Next, configure trusted hosts using Set-Item, set up authentication — either Kerberos or certificate-based — and make sure your connections are secure and encrypted, ideally using HTTPS. These steps help you stay secure while taking full advantage of remote administration.”
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.
Using PowerShell to invoke applications on remote computers has four primary benefits:
Schmalbach warned coders about the challenges posed by GUI applications and session isolation to remote application execution. “Running graphical programs remotely often fails because of session 0 isolation,” he advised. “The solution is to either stick to command-line tools or use PowerShell to trigger scheduled tasks that run in the user’s session. Also, build retry logic into your scripts — network hiccups happen, and your scripts should handle them gracefully.”
Durgut added, “You might run into problems with network configurations, firewall settings or permissions when running remote applications. To avoid these issues, make sure your network is set up correctly, configure firewalls to allow PowerShell remoting traffic and check that user accounts have the right permissions. Regular updates and patches can also help prevent compatibility problems.”
If you want to enhance your PowerShell capabilities further, consider learning about and experimenting with PowerShell modules next so you can organize and share your code more efficiently. Alternatively, learn about managing files over SFTP with PowerShell to seamlessly handle file transfers between remote systems.
Mark Fairlie contributed to this article.