Help removing package

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.

 

 

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.

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

https://pureinfotech.com/uninstall-apps-powershell-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.

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.

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.

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

[quote quote=119751]Are you admin on the remote computer? Is remote powershell enabled (can be a not easy task)?

[/quote]
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.

Does this work?

invoke-command computername { pwd } 

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.

[quote quote=119772]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.

[/quote]

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

[quote quote=119761][/quote]

Yes it does

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

[quote quote=119820]You could shorten all this when you simply post your code. 😉 Or is it a secret?

[/quote]

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)

 

 

 

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/

It’s always a good idea to post the complete code and error messages…

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

[pre]

$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’}

[/pre]

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

[pre]

$x = new-psession -computername (get-content C:\scripts\computers.txt)

invoke-command -session $x -filepath C:\scripts\installnewAV.ps1

[/pre]

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}