Home » PowerShell » Install Software with PowerShell Script Remotely

Install Software with PowerShell Script Remotely

PowerShell is a versatile scripting language that offers a powerful and flexible way to remotely install software using PowerShell scripts.

To install software with PowerShell remotely, you need to set up your environment for remote operations to connect the remote machine.

You can install the MSI package or Exe file on the remote machines using the combination of New-PSSession, and Invoke-Command cmdlets in PowerShell.

In this article, we will discuss how to install software using PowerShell scripts remotely.

Setting up the PowerShell Environment for Remote Operations

To connect to the remote machine, you need to set up your environment for remote operations. Use the command Enable-PSRemote cmdlet to enable PowerShell remoting on the target machine.

Enable-PSRemoting -Force

Next, create a remote session with the remote computer using the ‘New-PSSession‘ cmdlet:

$remoteSession = New-PSSession -ComputerName "EU-IT101"

In the above PowerShell script, the New-PSSession cmdlet uses the ComputerName parameter to specify the computer name or IP address.

Install MSI Package with PowerShell Remotely

To install an MSI package with PowerShell script remotely, follow the below steps:

  • Prepare MSI package: Create an MSI package for remote installation.
  • Copy MSI package to Shared Location: Copy the MSI software package to a shared location accessible by the remote computer.
  • Use the Invoke-Command to execute a script: Use the PowerShell Invoke-Command cmdlet that uses ScriptBlock to execute a script that executes the installation of software on the remote computer.
Invoke-Command -Session $remoteSession -ScriptBlock {
    Start-Process -FilePath "msiexec.exe" -ArgumentList "/i \\Shared\appSimulator.msi /qn" -Wait -NoNewWindow
}

In the above PowerShell script, the Invoke-Command uses the remote session object $remoteSession to execute the installation script on the target computer. It uses the msiexec.exe command to run Windows installer commands from the command line.

msiexec.exe command uses the arguments, like -i that specify normal installation and shared location and installation package file.

Install EXE files with PowerShell Remotely

To install an exe file with PowerShell script remotely, follow a similar process of MSI package installation.

Invoke-Command -Session $remoteSession -ScriptBlock {
    Start-Process -FilePath "\\Shared\app1.exe" -ArgumentList "/S" -Wait -NoNewWindow
}

In the above PowerShell script, the Invoke-Command cmdlet uses the -Session parameter to specify the $remoteSession object that contains the remote session with the target machine. It uses the ScriptBlock to execute the installation script to install the exe file on the remote machine.

Conclusion

I hope the above article on how to remotely install software with PowerShell scripts is helpful to you. By using the Start-Process and Invoke-Command cmdlets in PowerShell, you can efficiently manage the remote software installation process.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.