Powershell Script to Install and Uninstall Software

Powershell script to install software is so simple then doing it in the GUI. Today Powershell is doing a lot of changes to the windows environment that includes both the Server platform and the desktop platform. We can also use powershell script to uninstall software.


We can also use powershell script to install software remotely and vice versa. i.e. we can use powershell script to uninstall software remotely.

Whenever a version of powershell is released by Microsoft, there has been an upgrade in the core of the PowerShell and the application which was newly released was also getting the support to work with the powershell. This make us to use the powershell scripting environment to be friendly.

Installing and Uninstalling a software application using powershell commands are more easy than doing it in the GUI mode in Windows as i said earlier. It is because powershell commands allows us to use the software maintenance repository in windows in a good way so that we can dig in deep.

Advantages of using powershell to manage applications:

  • Easy to use
  • Higly secure and efficient.
  • Can install or uninstall a group of applications.
  • Can be scheduled to our convenience.
  • Application can be installed in remote computers.
  • Applications can be unistalled in remote computers.
  • Can maintain the remote computer software repository.

Dis-advantages of using powershell to manage applications:

  • Need to know the commands to execute.
  • Need Network Connectivity to manage remote computers.

One of the interesting feature which we can do using the powershell commands is we can install, uninstall or query the software details on the remote computers in a more convenient way. Lets look at how to install, uninstall, query the windows software applications using powershell script.

Before using the powershell remote execution command, enable the windows remote management service, by default it will be in the stop status. You can also run the below powershell query to configure the Windows Remote Management in the Powershell.

PS> winrm quickconfig
PS> Set-Item -force WSMan:\localhost\Client\TrustedHosts –Value *

[irp posts=”3607″ name=”Easy way to Configure your Powershell Profile”]

Powershell Script to list installed Windows Applications :

Using this powershell commands you can list the installed applications in your Computer, you need to mention the win32_product name to list the product which you are going to list.

PS> Get-WmiObject -Class Win32_Product

Using the below powershell command you can list the installed applications from the remote computer. Here the <remote_computer_name> refers to the computer to which you are going to connect and query the installed applications.



Before using this powershell command make sure you have a valid network connection between these two computer and also make sure you can connect to this computer. You may also need to know the administrator password of the remote computer which you are trying to connect.

PS> Get-WmiObject -Class Win32_Product -ComputerName <remote_computer_name>

Using this powershell command you can list the installed windows applications which was having the specific display name “Microsoft”. Instead of Microsoft you can use some other vendor name and can search the software repository.

PS> Get-WmiObject -Class Win32_Product -ComputerName . | Where-Object -FilterScript {$_.Name -eq "Microsoft"} | Format-List -Property *

[irp posts=”3165″ name=”How to install Windows features from Powershell”]

Powershell Script to Install Software :

Below is a powershell script, which was used to install the software using the powershell. Here Start-Process command was used to initiate the installation process of the package. Later Write-Host was used to display a message after the successful completion of software installation in Powershell windows.

PS> $setup=Start-Process "setup.exe" -ArgumentList "/s" -Wait

if ($setup.exitcode -eq 0)

write-host "Software Installed Succesfully"



[irp posts=”3158″ name=”How to install Windows updates manually using Powershell”]

Powershell Script to Install Software Remotely:

The below powershell command was used for installing the application in your remote system. Before executing this command, you need to make sure that you have a valid network connection between this two system. You also need to have a server share path to store the setup file.

PS> Invoke-Command -Computername $server -ScriptBlock {Start-process "\\servershare\Software\setup.exe"}

The below command was use to install the application in the remote system by passing the arguments. For e.g. you need to pass arguments for installing the Microsoft Office products. Likewise you also need to have a valid share path and network connection.

PS> Get-Service remoteregistry -ComputerName $computer | start-service Copy-item "\\$server\share\Software" -conatiner -recurse \\$computer\c$\windows\temp\ $InstallString = '"C:\windows\temp\Software\setup.exe" /adminfile Updates/SoftwareSetup.MSP /config Config.WW/config.xml"' ([WMICLASS]"\\$computer\ROOT\CIMV2:Win32_Process").Create($InstallString)



Powershell Script to Install Software Silently:

To install a software application silently, then you must add a switch at the end of the powershell command “/s”, this will install the application silently in your system. You can also use this switch to install the application in the remote computer silently.
PS> Start-Process 'Software\setup.exe' -ArgumentList "/s" -Wait

[irp posts=”3108″ name=”Powershell Command : Get-Command”] While runnign this command make sure that you have used the Wait switch at the end of the powershell command. because, you if not mention the switch, then the installation may not happen.

You also need to verify the installation application by running the powershell command which was used to check the powershell software repository.

Powershell Script to uninstall Software Silently:

We have seen how to install the application in your system and also in the remote system. Now we are going to see how to uninstall the application from the local computer using the powershell script. As the below powershell script says, it was very simple, you need to give the Software name for the “Name” variable, after that it will do the rest.
PS> $app = Get-WmiObject -Class Win32_Product -Filter "Name = '<Package Name>'"

PS> $app.Uninstall()

[irp posts=”3106″ name=”Powershell Command : Clear-Host”]

Powershell Script to uninstall Software Remotely:

Below is the powershell script to unstall the software application from the remote computer. In this script, you need to give the IP Address or the computer name of the target system, in whihc yuo are going to uninstall the software. Here make suure ot give the correct name of the software product whihc you are going to uninstall.

PS> $app = Get-WmiObject -ComputerName <IP Address> -Class Win32_Product -Filter "Name = '<Package Name>'"

PS> $app.Uninstall()



[irp posts=”3098″ name=”Powershell Command : Checkpoint-Computer”]

So these are some of the powershell scripts to install, uninstall and query the software applications from the software repository using the powershell. There are more other powershell commands which are used to maintain the software repository.

 Before using this powershell scripts, you need to make sure whether you are running the correct query, because a query executed by the powershell cannot be brought back. So don’t use the powershell scripts in the direct production system.

You may also like...

2 Responses

  1. Dan Brassard says:

    I will try tis powershell scripts..

  2. Deep Sahoo says:

    Thank you for the post, this is extremely helpful. However, I am not able to find a norestart switch to use with uninstall. Please let me know if there is any norestart switch that could be used to silently uninstall any application without rebooting the system.

Leave a Reply

Your email address will not be published. Required fields are marked *