How to Install an Application on a Remote Machine Using PowerShell

Although this seems as it would be a common tasks for administrators and developers alike, I found very little documentation on the Internet on how to install an msi or exe on a remote machine using PowerShell. I even found comments saying it couldn’t be done at all! Bull Hugly, it can be done! I have provided two pieces of code that you can use to install either an msi package or exe on a remote server using PowerShell.

Installing an MSI

Using a short hand of WMI in PowerShell , you can execute the following code to install your msi package:

$box=”deviis01” #this is the name of your server

$product= [WMICLASS]”\\$box\ROOT\CIMV2:win32_Product”

Write-Host “Installing software on $box”


$product.Install(“c:\Setup \somesoftwarepackage.msi”)

The best part is it will install it silently so you don’t have to worry about command arguments to do that.

Installing an EXE

The exe was more of a pain and I wasn’t able to get it to work with the Install method. If someone else is able to get it to work, please post a comment to share with the rest of us because I would like to know if it is possible, however, here is what you can do to install your exe.

$box=”deviis01” #this is the name of your server

Write-Host “Installing software on $box”

([WMICLASS]”\\$box\ROOT\CIMV2:win32_process”).Create(“cmd.exe /c c:\Setup\somesoftware.exe /s /v`” /qn”)

This actually works by creating a new process on the remote server, calling the cmd.exe and passing it the arguments for installing your program. One thing to make note of is all the command switches I have at the end. You will want to check your exe to see what switches it takes; for example mine above is using an exe created with InstallShield so the command line options might be different, so just keep that in mind.

-Flea#

Advertisements

5 Responses to How to Install an Application on a Remote Machine Using PowerShell

  1. Swapna says:

    The code to install MSI is not working
    Pls help me out on this

  2. Aman says:

    Hey Flea#,

    Thanks for silent msi installation code, it works and really helped me in my situation.

    • jaymin says:

      if u r having completed project that install .msi file using this code in .net than plz help me out n send me the whole source code so that can help me….expecting positive reply thank you in advance..
      my e mail id- sonijaymin@yahoo.com

  3. asp.net, c#,javascript…

    […]How to Install an Application on a Remote Machine Using PowerShell « Deep Conversations with Flea#[…]…

  4. darmowe filmy online…

    […]How to Install an Application on a Remote Machine Using PowerShell « Deep Conversations with Flea#[…]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: