uninstalling an application via uninstallString

Welcome Forums General PowerShell Q&A uninstalling an application via uninstallString

This topic contains 21 replies, has 7 voices, and was last updated by

 
Participant
1 month, 2 weeks ago.

  • Author
    Posts
  • #168754

    Participant
    Topics: 2
    Replies: 10
    Points: 31
    Rank: Member

    Hi guys, I am trying to uninstall an application on a remote server using uninstallstring, a property of Get-ItemProperty cmdlet in PowerShell, but failing to do so. I have also tried suggestions explained in another thread, click here to access the thread, however, my following script still do not uninstall the program, so please have a look.

    $computer = SERVER NAME
    invoke-command -computer $computer {
    $paths='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
    $app = Get-ChildItem -Path $paths | Get-ItemProperty | Where-Object {$_.DisplayName -like "*notepad*" }
    
    # $app.uninstallstring returns "C:\Program Files\Notepad++\uninstall.exe"
    Start-Process -FilePath cmd.exe -ArgumentList '/c', $app.uninstallstring  -Wait
    }
    

    I really appreciate your help.
    Faraz

  • #168766

    Participant
    Topics: 0
    Replies: 9
    Points: 75
    Helping Hand
    Rank: Member

    Faraz,

    There is a subtle misspelling in Line 3:

    $paths='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstal'

    At the end should be Uninstall.

    This would affect any 64-bit programs you are searching for.

    • #168775

      Participant
      Topics: 2
      Replies: 10
      Points: 31
      Rank: Member

      I was so embarrassed when you pointed out my silly mistake Chance F, however, when I checked my actual script, the location was correct there. Therefore, the mistake occurred while tweaking the text of the script on the textbox, before posting this thread. I have edited the script of the original post.

      Thank you for the reply 🙂

  • #168772

    Participant
    Topics: 0
    Replies: 9
    Points: 75
    Helping Hand
    Rank: Member

    Also, the ArgumentList parameter will need to be slightly adjusted:

    -ArgumentList '/c', $app.uninstallstring

    Could be:

    -ArgumentList "/c $($app.UninstallString)"

    Or you can add another line to account for the string combination:

    $processArgs = "/c " + $app.uninstallString
    Start-Process -FilePath cmd.exe -ArgumentList $processArgs  -Wait
    • #168814

      Participant
      Topics: 2
      Replies: 10
      Points: 31
      Rank: Member

      I have tried all your suggestions, but no luck as the application didn't uninstall.

  • #168829

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    can you print the uninstall string and share here.

    • #168862

      Participant
      Topics: 2
      Replies: 10
      Points: 31
      Rank: Member

      C:\Program Files\Notepad++\uninstall.exe

  • #168883

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    Try -ArgumentList "/c `"$($app.UninstallString)`""

    • #168931

      Participant
      Topics: 2
      Replies: 10
      Points: 31
      Rank: Member

      still doesn't work kvprasoon 🙁

  • #169078

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    You can print the uninstall string and check if its happening when you use the same in cmd with elevated permissions. For some applications I've seen that uninstall string doesn't work as is.

    • #169255

      Participant
      Topics: 2
      Replies: 10
      Points: 31
      Rank: Member

      Yes, I have tried running uninstall string in command prompt, elevated permissions, and I received UAC prompt in order to proceed the uninstall. So, is there any way to bypass UAC in PowerShell to accomplish this task?

  • #169279

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

    Well, you can't bypass UAC for an execution. But you can disable(not really recommended) it by updating UAC setting registry key.

    • #169456

      Participant
      Topics: 2
      Replies: 10
      Points: 31
      Rank: Member

      Yes, I have been searching ways to bypass UAC, but didn't find any workable suggestion\solution.

      Moreover, I was trying to create an answer file in order to capture the inputs from the uninstall process, and thereby executing uninstall.exe, the file where uninstallstring points to, silently. However, I am unsuccessful so far.

  • #169291

    Participant
    Topics: 0
    Replies: 44
    Points: 235
    Helping Hand
    Rank: Participant

    To get around UAC, try running the MSIEXEC command . if you run the script as the local SYSTEM account, in that case it shouldn't ask for UAC and all remote commands are actually running under the SYSTEM account.
    So, can use below line in your code and try
    Example:
    MSIEXEC /quiet /x $($app.uninstallstring)

    • #169459

      Participant
      Topics: 2
      Replies: 10
      Points: 31
      Rank: Member

      Thanks for the post Evila, the suggestion didn't work. Although the example you gave didn't return any error in PS ISE or command prompt, the application was still on the computer.

  • #169507

    Participant
    Topics: 0
    Replies: 1
    Points: 36
    Rank: Member

    Try this command to silently uninstall Notepad++ (using the "/S" switch – it is case sensitive and must be a capital "S"):

    Start-Process -FilePath "$($app.UninstallString)" -ArgumentList '/S' -Wait
  • #169519
    js

    Participant
    Topics: 25
    Replies: 678
    Points: 1,629
    Helping Hand
    Rank: Community Hero

    Grrr, why doesn't this work? No error given either.

    get-package notepad++* | Uninstall-Package -verbose
    
    • #169585

      Participant
      Topics: 0
      Replies: 4
      Points: 29
      Rank: Member

      This would only work if you installed via MSI. There isn't an official MSI for Notepad++.


      On a side note, if you did have an MSI install and you wanted it to uninstall I would suggest running the following first. It would allow you to see the exact name you would need to uninstall the MSI package

      get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize

      Then you enter that exact name where "Software Name" is and the MSI install will be no more.

      Get-Package -Name "SOFTWARE NAME" | Uninstall-Package -Force
  • #169705
    js

    Participant
    Topics: 25
    Replies: 678
    Points: 1,629
    Helping Hand
    Rank: Community Hero

    A workaround for notepad++ I was just given. It won't be a silent uninstall though.

    get-package *notepad* | % { & $_.Meta.Attributes["UninstallString"]}
    
  • #169723

    Participant
    Topics: 0
    Replies: 4
    Points: 29
    Rank: Member

    A workaround for notepad++ I was just given. It won't be a silent uninstall though.

    1
    2
    get-package *notepad* | % { & $_.Meta.Attributes["UninstallString"]}
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Well, you learn to do something in a new and different way. Didn't realize this could be done in this manner. Thanks

    Now just to tie in the Silent uninstall since who wants to look at the uninstaller and just get it done quickly.

    • #169783
      js

      Participant
      Topics: 25
      Replies: 678
      Points: 1,629
      Helping Hand
      Rank: Community Hero

      Here's the silent uninstall of notepad++:

      get-package notepad++* | % { & $_.Meta.Attributes["UninstallString"] /S}
      
    • #169822

      Participant
      Topics: 0
      Replies: 4
      Points: 29
      Rank: Member

      LOL, I thought that was going to be simple.

      Thanks

You must be logged in to reply to this topic.