Help removing package

Welcome Forums General PowerShell Q&A Help removing package

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

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #119402

    Participant
    Points: 55
    Rank: Member

    I have been struggling for hours now trying to figure out how to uninstall programs via powershell

    I have tried uninstall-package in every variety I can find, it does nothing even though it acts as if removes it

    get-package -providername programs -includewindowsinstaller -name"avast free antivirus" |uninstall -force

    also  Get-WmiObject -class win32_product -ComputerName "localhost"  does not even list the package. Very frustrating, programs and features removes it just fine, you'd think this would be fairly straight forward in powershell.  Need to do this across multiple computers, why I am trying to figure it out on powershell. Sure its got to be more complicated then this, any help would be appreciated.

     

     

  • #119455

    Participant
    Points: 245
    Helping Hand
    Rank: Participant

    Usually you find the uninstall strings in the registry and you can invoke this to uninstall applications just like the "programs and features" does it.
    You should search for 64 bit applications in HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall and for 32 bit applications in HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall.

  • #119518

    Participant
    Points: 307
    Helping Hand
    Rank: Contributor

    Did you install this from the MS Store or from somewhere else.

    If it was from the store, then it's ...

    Get-AppxPackage | RemoveAppxPackage

    … there are lots of articles all over the web on the topic … Example(s) …

    How to uninstall a Windows Store app using PowerShell

    https://answers.microsoft.com/en-us/windows/forum/windows_8-winapps/how-to-uninstall-a-windows-store-app-using/85ecc099-3de0-406e-a629-8c6c83ef8abe

    How to uninstall apps using PowerShell on Windows 10

    ... and there are already scripts / tools for this, that is if you don't want to write them yourself.

    Windows 10 Store Apps Uninstaller (PowerShell/WinForms)
    If you no longer need an app, then you could use Windows 10 Store Apps Uninstaller to remove it and free up space on the drive.
    https://gallery.technet.microsoft.com/scriptcenter/Windows-10-Store-Apps-5f60b9e3/view/Discussions

    Remove Windows Store apps in Windows 8, Windows 8.1 and Windows 10
    This script can be used to remove multiple Windows Store apps from a user account in Windows 8, Windows 8.1 and Windows 10. It provides a list of installed Windows Store apps. You can specify the application IDs, and remove them all at
    https://gallery.technet.microsoft.com/scriptcenter/Remove-Windows-Store-Apps-a00ef4a4

    Otherwise the registry uninstall location pointed to by Olaf and avoid using win32_product at all costs. It does some unwanted things, several articles on the web about that as well.

  • #119667

    Participant
    Points: 55
    Rank: Member

    Thanks for the help, I have it figured out.  Running into a new problem, I have created a .bat file to install my new AV.  I have created the domain policy's to enter-pssession and that works fine.  However once I'm on the remote computer and I try it execute the .bat I get permission denied.  I have also tried to use invoke-command on the remote pc with the same error.  cmdlt I am trying to run is (start-process -computername -filepath) with and without -credentials. I am a domain admin in the network.

    • #119721

      Participant
      Points: 245
      Helping Hand
      Rank: Participant

      There is unfortunately little to no chance for us to help you without seeing your code. If you post code please format it as code. Thanks.
      You can edit your post to include the code if you want.

  • #119751
    js

    Participant
    Points: 315
    Helping Hand
    Rank: Contributor

    Are you admin on the remote computer? Is remote powershell enabled (can be a not easy task)?

  • #119757

    Participant
    Points: 55
    Rank: Member

    Are you admin on the remote computer? Is remote powershell enabled (can be a not easy task)?

    It is domain joined so yes I am an admin on the computer.  Not sure what you mean by remote powershell, I have my GP set to "allow remote server management through WinRM", appropriate firewall ports opened and WinRM server starting automatically on pc's.

    • #119761
      js

      Participant
      Points: 315
      Helping Hand
      Rank: Contributor

      Does this work?

      invoke-command computername { pwd } 
      
  • #119772

    Participant
    Points: 9
    Rank: Member

    Is the batch file or AV installer you're trying to run on different remote system?  Sounds like you're running into the double-hop problem.

  • #119773

    Participant
    Points: 55
    Rank: Member

    Is the batch file or AV installer you're trying to run on different remote system? Sounds like you're running into the double-hop problem.

    Yes, the .bat file resides on a server share, I have heard of this issue but not sure what it means?

  • #119776

    Participant
    Points: 55
    Rank: Member

    Yes it does

  • #119820

    Participant
    Points: 245
    Helping Hand
    Rank: Participant

    You could shorten all this when you simply post your code. 😉 Or is it a secret?

  • #119850

    Participant
    Points: 55
    Rank: Member

    You could shorten all this when you simply post your code. 😉 Or is it a secret?

    Your right I should have posted it to begin with, sorry:

    launch powershell as administrator >

    enter-pssession -computername d1 (this works)>

    [d1]: ps c:\>start-process -filepath "\\dc-server1\softwaredeploy\install.bat" (access denied)

    [d1]: ps c:\>start-process -filepath "\\dc-server1\softwaredeploy\install.bat" -credentials (access denied after entering local and domain credentials)

    invoke-command -computername "d1" {start-process -filepath "\\dc-server1\softwaredeploy\install.bat"} (access denied)

     

     

     

  • #119907

    Participant
    Points: 70
    Rank: Member

    This is the classic double hop problem Neemobeer mentioned. You're remoting from one machine to d1 (1st hop) all okay here. Then your trying to get to \\dc-server1 (2nd hop) no go I'm afraid as you have not set d1 to be able to delegate your credentials to DC-server1. Check out this by Ashley Mcglone on how to get this to work.

    https://blogs.technet.microsoft.com/ashleymcglone/2016/08/30/powershell-remoting-kerberos-double-hop-solved-securely/

  • #120121
    js

    Participant
    Points: 315
    Helping Hand
    Rank: Contributor

    It's always a good idea to post the complete code and error messages...

  • #120124
    Jon

    Participant
    Points: 35
    Rank: Member

    I recently did an AV migration and handled it the following way:

    1. Create a GPO that pushes out the AV exe and associated scripts out to the machine
    2. Create a text file with all the server names you want to push out the AV to
    3. Use invoke-command to install the software

    My code was something like this

    
    $x = new-psession -computername (get-content C:\scripts\computers.txt)
    
    invoke-command -session $x -scriptblock {Start-Process -FilePath 'C:\mcafee\McAfeeAgent5.5.exe' -ArgumentList '/install=agent /silent'}
    
    

    You could also do something like this, which assumes the script is installed on the machine you are running powershell from

    
    $x = new-psession -computername (get-content C:\scripts\computers.txt)
    
    invoke-command -session $x -filepath C:\scripts\installnewAV.ps1
    
    
  • #120223

    Participant
    Points: 55
    Rank: Member

    I appreciate all the help, that article explained what I was doing wrong.  I put the following script together, and it's working. Hope maybe this helps someone else out.

     

    $session = New-PSSession -ComputerName d1
    Copy-Item -Path "C:\folder\*.*" -ToSession $session -Destination 'c:\windows\temp'

    Invoke-Command -Session $session -ScriptBlock {
    c:\windows\temp\install.bat /silent}

    Invoke-Command -session $session {Get-ChildItem -Path "c:\windows\temp\install*.*" |Remove-Item}

You must be logged in to reply to this topic.