Need a script that will uninstall multiple programs

Welcome Forums General PowerShell Q&A Need a script that will uninstall multiple programs

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #6082

    Points: 0
    Rank: Member

    by the_ratzenator at 2013-04-30 23:51:01

    I would like to have a script that uninstalls all software on a computer and offers a wait state during each uninstall and moves onto the next program to uninstall. How would I go about doing this? Thanks

    by poshoholic at 2013-05-01 12:25:12

    Initial thoughts that come to mind:
    1. Enumerate installed programs by querying the Windows Registry.
    2. For each installed program, identify the uninstall command (also from the Registry).
    3. Invoke the uninstall command for each program, one at a time, using Start-Process with the -Wait parameter. Be careful to invoke the uninstall with whatever switches are required to make it silent. An alternative to using -Wait on Start-Process (which will wait forever), you could invoke Start-Process without wait, grab the process object it returns, and then go into a while loop while counting a timer, sleeping for 1 second every iteration, and make sure that you only wait a maximum of X seconds before you determine that the uninstall failed, reporting an error message to the user in this case.
    4. Wrap it up in a script block and invoke it on a remote system using Invoke-Command.

    Something like that should do the trick.

    by the_ratzenator at 2013-05-02 00:28:35

    Thanks Kirk

    Here is some code I am trying to tweak that I got from I am stuck and need some help. Thanks

    Function Get-UninstallString
    < #
    Get-Uninstall string provides the DisplayName, Publisher and UninstallString for all software listed in the registry

    Get-Uninstall will query the x64 and x86 registry nodes in order to list out all installed software and there associated uninstall stings. By default information is displayed as a table in a custom PSObject.

    .PARAMETER ComputerName


    Product : VMware Tools
    Company : VMware, Inc.
    Computer : LABTOOLS
    Uninstall : MsiExec.exe /X{44D55920-B223-4702-81D9-4C07108A3C27}
    Version :

    Product : Microsoft Visual C++ 2008 Redistributable – x64 9.0.30729.6161
    Company : Microsoft Corporation
    Computer : LABTOOLS
    Uninstall : MsiExec.exe /X{5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4}
    Version : 9.0.30729.6161

    Product : Microsoft Visual C++ 2008 Redistributable – x86 9.0.30729.4148
    Company : Microsoft Corporation
    Computer : LABTOOLS
    Uninstall : MsiExec.exe /X{1F1C2DFC-2D24-3E06-BCB8-725134ADF989}
    Version : 9.0.30729.4148

    Get-UninstallString | Format-Table

    Product Company Computer Uninstall Version
    ——- ——- ——– ——— ——-
    VMware Tools VMware, Inc. LABTOOLS MsiExec.exe /X{44D55920-...
    Microsoft Visual C++ 2008... Microsoft Corporation LABTOOLS MsiExec.exe /X{5FCE6D76-... 9.0.30729.6161
    Microsoft Visual C++ 2008... Microsoft Corporation LABTOOLS MsiExec.exe /X{1F1C2DFC-... 9.0.30729.4148

    Get-content c:\servers.txt | Get-UninstallString

    Gets the uninstallstring information for a list of computers specified in the file servers.txt

    )][String[]]$ComputerName = $env:COMPUTERNAME
    $param = @{ScriptBlock = {`
    if ((Get-WmiObject win32_operatingsystem -ComputerName $ComputerName).OSArchitecture -notlike '64-bit') {$keys= (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*')}
    else {$keys = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*')}
    $Keys |
    Where-Object {$_.Publisher -or $_.UninstallString -or $_.displayversion -or $_.DisplayName} |
    ForEach-Object {
    New-Object -TypeName PSObject -Property @{
    Computer = $env:COMPUTERNAME
    Company = $_.Publisher
    Uninstall = $_.UninstallString
    Version = $_.displayversion
    Product = $_.DisplayName
    If (Test-Connection $ComputerName -Quiet -Count 2) {
    If ($ComputerName -ne $env:COMPUTERNAME) {$param.Add("ComputerName",$ComputerName)}
    Invoke-Command @param
    Else { "The Computer, $ComputerName, is not online" }
    End {}

    #This is where I am stuck

    $UninstallStr= (Get-UninstallString).Uninstall | Select-String "msiexec.exe /X"

    Foreach ($Str in $UninstallStr)

    by poshoholic at 2013-05-02 05:55:31

    You should take an approach something like this instead:

    foreach ($uninstallString in Get-UninstallString | Select-Object -ExpandProperty Uninstall) {
    Write-Verbose $uninstallString # This line is optional, just added in case you want to troubleshoot with verbose messages. You could use Write-Debug instead since it's really more of a debugging thing.
    # Now call start-process with the uninstall string information

    by the_ratzenator at 2013-05-02 14:14:22

    I will try that and get back with you Kirk. Thanks.

    I can always ask if we can contract out, but I work in a large healthcare environment with one particular PowerShell guru located in another state and I would ask him, but he has a tendency of really pissing me off with his arrogant smartass mouth, so that is why I am here inquiring.

The topic ‘Need a script that will uninstall multiple programs’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort