Share via


Function in PowerShell script to uninstall program

This script helps you to uninstall programs using PowerShell as to make it dynamic I made it as function so you can bypass the name of the program that you want to uninstall it

  function uninstallapp ($x) { $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "$x" } $app.Uninstall() } 

Here you can find how to run it

PS C:\Windows\system32> uninstallapp "microsoft lync 2010"

below you will get result like this one

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0