Goto Top

Powershell Uninstall-Package

Hello guys,

sorry for my bad english face-smile

i'm trying to create a powershell script to uninstall software on a remote machine.
i enter the machine name, get the installed software as enumeration and prompt the number for the specific software.

This is what i have

Unfortunately, it doesn't work for me. In the Uninstall-function i get the following failure:
"The argument cannot be bound to the name parameter because it is an empty string."

I hope you can help me face-smile


Content-Key: 656544


Printed on: December 3, 2022 at 12:12 o'clock

Mitglied: 147669
Solution 147669 Feb 26, 2021 updated at 08:37:49 (UTC)
Goto Top
Hi Natalie,
your problem is that you are defining a local Variable $iNi which does not exist on the remote side when you call the command via Invoke-Command.
To use this variable on the remote side you can either pass it as a parameter to Invoke-Command by using the -Argumentlist parameter or use the special Variable-Prefix $using: in the remote scriptblock to access local session variables
Invoke-Command -ComputerName $pcname -ScriptBlock { Get-Package -Name $using:iNi | Uninstall-Package -Force}
Have a closer look at the docs for detailed explanations: ...

Best regards
Member: natalie.solero
natalie.solero Feb 26, 2021 updated at 08:27:35 (UTC)
Goto Top
thank you so much for your answer face-smile
i just tried your solution but it also doesn't work for me. Now it says it can't find a package with this name. I't doesn't matter which software i choose. It is strange because at first it shows me all installed software.

I have figured out, that when i am using
it works for a couple of software but not for all.
Any Ideas?
Mitglied: 147669
147669 Feb 26, 2021 updated at 08:57:18 (UTC)
Goto Top
it works for a couple of software but not for all.
Not every software can be uninstalled with this cmdlet only specific ones. Here you have to to it via CIM/WMI to uninstall.
Member: natalie.solero
natalie.solero Feb 26, 2021 at 09:25:28 (UTC)
Goto Top
That is really crazy...
If i use the get-package command i can see all installed software on the remote machine, for example GIMP but i can't uninstall it.
If i try it with
i can't see it is not passible to deinstall GIMP
Mitglied: 147669
Solution 147669 Feb 26, 2021 updated at 09:40:31 (UTC)
Goto Top
No, thats totally normal in MS environment! The reason is, if a software installer has not registered with windows installer it does not appear in this list. So you have to grab the registry key UninstallString key for this software and invoke the uininstall command with silent switches.


Welcome to super duper "Winblows Package Management" face-wink ... If i were you i would switch to choclately or another software package manager like WSUS PP and so on.

Wish you success. I'm out.

Member: chkdsk
Solution chkdsk Feb 26, 2021 at 12:05:04 (UTC)
Goto Top
Hello Natalie,
to be sure, you can combine both methods from @147669. Maybe he has another idea face-smile
But i'm not sure if it's getting all software or is able to uninstall, please test it yourself.