Remote install an msi with Powershell

Remote install an msi with Powershell?

I know I have had to do this many times but there are many pitfalls to be wary of. Here is the simplest method to get that pesky msi to install now on a remote computer with Powershell.

Problem

You are on your admin workstation and you want to install an msi which I will call ‘installer.msi’ on at least one machine in your domain. Installer.msi is located on a file server on the network.

Solution

A Powershell script that copies the file to the local machine, installs the msi then deletes installer.msi from the local machine. How do you do this, simple.

copy-item copy-item -Path \\fileserver\share\installer.msi -Destination \\machine-to-instal-to\c$\temp\installer.msi
Invoke-WmiMethod -Path Win32_Product -Name Install -ComputerName "machine-to-install-to" -ArgumentList @($true,$null,"\\machine-to-install-to\c$\installer.msi")
remove-item -path  \\machine-to-instal-to\c$\temp\installer.msi

I have found this is the simplest method. Obviously you should consider wrapping this in a try catch and putting it in a loop to install on a set of computers.

I have had some success with using invoke-command calling start-process and this is probably the best method if you want to install an exe rather than an msi.

Why

Why not use a GPO I hear you shout? Simple. GPO’s do not offer the flexibility. I use this when I want to install it now, not when the computer next reboots, or if I want to do some pre/post processing like copying a config file around. You may need to use a similar method if you have a badly written service that doesn’t stop for the installer.