How to Install Software Remotely Using PowerShell | Step-by-Step Guide

In this article, I will guide you on how to remotely install software using PowerShell, a default tool in Windows.

Unlike PSExec, PowerShell is already installed on your computer, making it more accessible to use.

This step-by-step guide covers the prerequisites, how to meet the requirements, and how to write a PowerShell script to remotely install a software package.

Pre-requisites

  1. Access to the remote computer: You must have administrative access to the remote computer to install software remotely using PowerShell. Either you need to have the local administrator password if the computer is in WORKGROUP or a domain administrator password if the computer is a part of the domain network.
  2. PowerShell remoting enabled: PowerShell remoting must be enabled on both the local and remote computers. This can be done by running the following command on both computers: Enable-PSRemoting -Force. The “Force” argument suppresses the user prompts.
  3. Firewall configuration: If a firewall is in place, you need to ensure that it is configured to allow PowerShell remoting traffic. Running the Enable-PSRemoting -Force command will create a firewall exception to enable Powershell remoting traffic.
  4. Software installation package: You should have the installation package for the software that you want to install on the remote computer. This can be a .EXE or .MSI package.

Note: If you want to deploy Software on computers in a domain network, meeting conditions 2 and 3 could be daunting if doing it manually on each computer. There is a better way of doing it automatically through a group policy (GPO). I will discuss that in this article.

Meeting The Requirements

Access to the remote computer

Assuming the remote computer is in a domain, and you have a domain administrator account.

Enable PowerShell Remoting

To enable PowerShell remoting, run the following PowerShell command on both local and remote computers:

Enable-PSRemoting -Force

To enable PowerShell remoting on all your domain computers, use a group policy to allow Windows Remote Management, configure Windows Firewall, and configure Windows Remote Service.

1: Enable Windows Remote Management Through GPO

On a domain controller, open the Group Policy Management console (GPMC).

Expand the forest, domain, and organizational unit (OU) where you want to create the GPO.

Navigate to Computer Policies > Administrative Templates > Windows Components > Windows Remote Management (RM) > WinRM Service. Then, double-click Allow Remote Server Management Through WinRM Policy.

Select the radio button next to Enabled and place the “*” for each line in the text box next to IPv4 and IPv6. Click OK to save the settings.

2: Configure Firewall Settings Through GPO

Note: WinRM will be set to allow connections from any IPv4/IPv6 addresses when using the “*”. If you want to secure access to a specific IP address or IP range, enter that in the textbox instead.

While still in the Group Policy Management Console, navigate to the following path: Computer Policies > Windows Settings > Security Settings > Windows Firewall with Advanced Security

Expand the selection, right-click on “Inbound Rules” then click on “New Rule

Select the Radio button next to “Predefined“, then in the drop-down menu, select “Windows Remote Management“. Click Next to continue.

Two predefined rules will be created; uncheck the “Windows Remote Management (HTTP-In)” for the public profile. You don’t want to allow remote access when the computer (Laptop) is in a public network (Public Wi-Fi).

Select the “Allow the Connection” option and click Finish to complete the configuration.

The new rule is now configured and displayed in the GPMC

3: Configure Windows Remote Service Through GPO

The final step is configuring the “Windows Remote Management (WS-Management)” service.

While still in the GPMC, navigate to Computer Policies > Windows Settings > Security Settings > System Services.

Double-click the Windows Remote Management (WS-Management) service to configure the properties.

In the new window that opens, check the Define This Policy Setting option and select Automatic under Select Service Startup Mode. Click OK to save the settings.

Note: The group policy could take up to 90 minutes to be effective. You can, though, force the GPO to apply on the remote host by running the following command:

gpupdate /force

Download the Software Installation Package

Now, you need to download the Installation package of the Software you want to install.

There are two types of Installation programs: online and offline Installer.

For your remote installation, you need to download the offline Installer, which contains all the necessary files to perform the installation, without having to connect to the internet to download the missing files.

How do you find the offline Installer?

By default, most software editors offer the online Installer, and often, it’s not easy to find the offline Installer navigating through their website menu.

The quickest way to find it is to do a Google search. For example, to download the Mozilla Firefox browser, type the following keywords: “Mozilla Firefox offline installer

The Powershell Script

Now that you have met the prerequisites, write the PowerShell script to install the software installer package you downloaded remotely.

In this article, I will give you two scripts, one for deploying a .EXE installer package and a second for deploying a .MSI package.

Let’s say you have downloaded the Firefox Installer on Computer A and want to install it on Computer B.

To keep things simple, we will put the installer package in the C:\Temp folder on Computer A

  1. We must copy the installer package from computer A to computer B (in the C:\Temp Folder).
  2. Run the Installer on computer B
  3. When the installation is complete, we remove the installer package from computer B

Deploying the EXE Installer Package

The PowerShell script will look like this:

# Define the remote computer name and Software installation package path
$ComputerName = " RemoteComputerName"
$DestFolderPath = "C:\Temp"
$FilePath = "C:\Temp\ Firefox Setup 112.0.2.exe"

# Create a new PowerShell session to the remote computer
$Session = New-PSSession -ComputerName $ComputerName

#Create the destination folder if not already exist
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
param($DestFolderPath)
if (!(Test-Path $DestFolderPath)) {
}
} -ArgumentList $DestFolderPath

# Copy the software installation package to the remote computer
Copy-Item $FilePath -Destination $DestFolderPath -ToSession $Session

# Install the Software silently on the remote computer
Invoke-Command -Session $Session -ScriptBlock {
param($FilePath)
Start-Process -FilePath $FilePath -ArgumentList "/silent" -Wait} -ArgumentList $FilePath

# Remove the installation package from the remote computer
Invoke-Command -ComputerName $ComputerName -ScriptBlock { 
param($FilePath) 
Remove-Item $FilePath -Force -Recurse } -ArgumentList $FilePath


# Close the PowerShell session to the remote computer
Remove-PSSession $Session

Note: You can remotely install an EXE package if it supports the silent installation. Otherwise, you need to consider using the MSI package instead.

Deploying the MSI Installer Package

# Define the remote computer name and MSI package path
$ComputerName = "RemoteComputerName"
$DestFolderPath = "C:\Temp"
$FilePath = "C:\Temp\Firefox Setup 112.0.2.msi"

# Create a new PowerShell session to the remote computer
$Session = New-PSSession -ComputerName $ComputerName

#Create the destination folder if not already exist
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
param($DestFolderPath)
if (!(Test-Path $DestFolderPath)) {
}
} -ArgumentList $DestFolderPath

# Copy the MSI package to the remote computer
Copy-Item $FilePath -Destination $DestFolderPath -ToSession $Session

# Install the MSI package on the remote computer
Invoke-Command -Session $Session -ScriptBlock {
param($FilePath)
cmd /c start /wait msiexec /i $FilePath /quiet} -ArgumentList $FilePath

# Remove the MSI package from the remote computer
Invoke-Command -ComputerName $ComputerName -ScriptBlock { 
param($FilePath) 
Remove-Item $FilePath -Force -Recurse } -ArgumentList $FilePath

# Close the PowerShell session to the remote computer
Remove-PSSession $Session

Using the IP address instead of the computer name

We have used the remote host computer name in the above scripts to deploy the Software. What if you want to use the remote host IP address instead?

You must add the IP address of the remote host as a trusted IP address to run PowerShell commands on that remote host.

You do that by running this PowerShell command on your computer:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.0.10" 

Configure the trusted IP through a GPO

Using the group policy to specify the trusted IP address on multiple computers on your domain would be best.

Open the group policy management console and edit the GPO you previously created, then navigate to Computer Policies > Administrative Templates > Windows Components > Windows Remote Management (RM) > WinRM Client.

Then, Edit Trusted Hosts.

Select the radio button next to Enabled in the newly displayed window and type the IP address in the text box next to TrustedHostList. Click OK to save the settings.

Note: The group policy could take up to 90 minutes to be effective. You can, though, force the GPO to apply on the remote host by running the following command:

gpupdate /force

How to remotely install Software on multiple computers

The above scripts are perfect for deploying Software on one remote computer at a time. But what if you want to perform this action on several computers?

Here is the PowerShell script to remotely install a Firefox EXE installer on multiple computers:

# Define the software installation package path
$FilePath = "C:\Temp\Firefox Setup 112.0.2.exe"
# Define the folder path on the remote computer where to copy the install package
$DestFolderPath = "C:\Temp"
# Read the list of remote computers from a file
$ComputerNames = Get-Content "C:\Temp\ComputerList.txt"

# Iterate through each remote computer and deploy the Software
foreach ($ComputerName in $ComputerNames) {
    # Create a new PowerShell session to the remote computer
    $Session = New-PSSession -ComputerName $ComputerName
    
    # Create the destination folder if it doesn't already exist on the remote computer
    Invoke-Command -Session $Session -ScriptBlock {
        param($DestFolderPath)
        if (!(Test-Path $DestFolderPath)) {
            New-Item $DestFolderPath -ItemType Directory | Out-Null
        }
    } -ArgumentList $DestFolderPath
    
    # Copy the software installation package to the remote computer
    Copy-Item $FilePath -Destination $DestFolderPath -ToSession $Session
    
    # Install the Software silently on the remote computer
    Invoke-Command -Session $Session -ScriptBlock {
        param($FilePath)
        Start-Process -FilePath $FilePath -ArgumentList "/silent" -Wait
    } -ArgumentList $FilePath
    
    # Remove the installation package from the remote computer
    Invoke-Command -Session $Session -ScriptBlock {
        param($FilePath)
        Remove-Item $FilePath -Force -Recurse
    } -ArgumentList $FilePath
    
    # Close the PowerShell session to the remote computer
    Remove-PSSession $Session
}

This script reads the list of remote computers from a file named “ComputerList.txt” located in the “C:\Temp” directory of the computer from where you run the PowerShell script. You can modify the file path and name according to your requirements.

The script then iterates through each remote computer and deploys the Software using the same approach as in the previous scripts.

Mistakes to avoid when remotely installing Software on Windows

  1. Not checking system requirements: Before installing any software, it’s essential to check the system requirements to ensure that the Software is compatible with the target PC’s operating system and hardware.
  2. Not testing the installation process: Before installing Software remotely, it’s a good idea to test the installation process on a test machine to ensure that everything works as expected. This will help you identify and fix any issues before deploying the Software to production machines.
  3. Not having proper permissions: To install Software remotely, the user must have appropriate permissions to access the target PC. The installation process may fail if the user does not have the necessary permissions.
  4. Not checking for conflicts: Installing new Software on a computer with conflicting Software can cause unexpected problems. Before you install any software remotely, ensure there are no conflicts with existing Software.
  5. Not communicating with end-users: When you remotely install Software on a user’s computer, it’s important to communicate with the user to let them know what to expect. This can include letting them know when the installation will take place and what steps they need to take, if any.
  6. Not having a backup plan: Even with careful planning and testing, things can go wrong during the remote installation. It’s essential to have a backup plan in place in case something goes wrong. This can include having a plan to roll back the installation or having a backup image of the computer.

Conclusion

With this step-by-step guide, you can now remotely install software on a computer using PowerShell.

Following the prerequisites, meeting the requirements, and writing the PowerShell script are essential for a successful installation.

PowerShell is a powerful tool that can save time and effort for system administrators who need to manage multiple computers.

Share this article

1 thought on “How to Install Software Remotely Using PowerShell | Step-by-Step Guide”

  1. Pingback: How To Deploy Software Using Group Policy - ZineTek

Leave a Reply