Author Posts

July 26, 2018 at 7:48 am

hello guys ...
im trying to uninstall a software " oracle virtualbox " so i made a simple powershell script

Invoke-Command -ScriptBlock {Get-CimInstance -ClassName Win32_Product -ComputerName (Get-Content D:\Powershell\Computernames.txt) -Filter "name like '%virtualbox%'" | Remove-CimInstance -Verbose}

... but for some reason it only works if im logged on to the remote pc via Remote desktop ... though the -verbose shows that its performing some actions

VERBOSE: Perform operation 'Delete CimInstance' with following parameters, ''namespaceName' = root/cimv2,'instance' = Win32_Product: Oracle VM VirtualBox 5.1.
22 (IdentifyingNumber = "{8D5E4D4D-5E0C-4448-B018-5DDEF1E208D9}", Name = "Oracle VM VirtualBox 5.1.22", Version = "5.1.22")'.
VERBOSE: Performing the operation "Remove-CimInstance" on target "Win32_Product: Oracle VM VirtualBox 5.1.22 (IdentifyingNumber = "{8D5E4D4D-5E0C-4448-B018-5D
DEF1E208D9}", Name = "Oracle VM VirtualBox 5.1.22", Version = "5.1.22")".
VERBOSE: Perform operation 'Delete CimInstance' with following parameters, ''namespaceName' = root/cimv2,'instance' = Win32_Product: Oracle VM VirtualBox 5.1.
22 (IdentifyingNumber = "{8D5E4D4D-5E0C-4448-B018-5DDEF1E208D9}", Name = "Oracle VM VirtualBox 5.1.22", Version = "5.1.22")'.
VERBOSE: Operation 'Delete CimInstance' complete.
VERBOSE: Operation 'Delete CimInstance' complete.
VERBOSE: Operation 'Delete CimInstance' complete.

any help please ?

July 26, 2018 at 1:29 pm

This is not a Pester question. Moving to the correct forum.

July 26, 2018 at 1:31 pm

Many installers are badly made and won't work without a full user profile; PowerShell Remoting does not create a full user profile. Short of repackaging the software into a better installer, there's not much you can do about that.

July 26, 2018 at 4:11 pm

How was the software installed?

Why not copy your script to a shared location, and set it as a RunOnce option on the users systems?
Why not remotely create a scheduled task, which runs once at user logon, to remove the software?
If the software was install via a tool like SCCM then use SCCM to remove it?
If the software was installed using GPO, then it can be removed with GPO?

How about changing this up a bit.

Get-Content 'D:\Powershell\Computernames.txt' %{
"Processing actions on $_"
Invoke-Command -ComputerName $_ -ScriptBlock {Get-CimInstance -ClassName Win32_Product -Filter "name like '%virtualbox%'"}
}

Also, Win32_Product can be very slow and has other issues...

'gregramsey.net/2012/02/20/win32_product-is-evil'

'powershell.org/forums/topic/alternatives-to-win32_product'

… so, depending on your scenario, it's best to use an alternative.

July 27, 2018 at 4:37 am

the software was installed one by one pc ... i will try your suggestions thanks