Sign in to follow this  
Followers 0
Chimaera

Trying to test a modern way of uninstalling

7 posts in this topic

Having trouble with modern installshield uninstallers as they seemed to have changed stuff, so i was trying to make a basic uninstaller to test my theory that it may need PS to do the uninstall

$uninstall = (Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*").uninstall()

Im using the above but it gives this error

PS C:\windows\system32> $uninstall = (Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*").uninstall()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $uninstall = (Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*").un ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

PS C:\windows\system32>

I thought i had sorted the null by adding 

$uninstall =

Some help please

Share this post


Link to post
Share on other sites



This part is null:

(Get-WmiObject Win32_Product | Where Name -eq "*PowerDirector*")

So the call to the uninstall method will not work. It's like trying to do this:

($null).uninstall()

So PowerShell is telling you, it is literally impossible to call a member function of something that is not. It doesn't even get to the variable assignment part because evaluating the expression on the right hand side failed, so what value should it put?

I think the reason it's not "clicking" for you is because it is all written on a single line and you're used to AutoIt where everything is written out on many lines. So you're confused about the order in which it is run. Try writing the same thing as you would write it in AutoIt.

Share this post


Link to post
Share on other sites

PS <> WQL, that is the biggest mental hurdle i see ( often directly in my own path :) ).  You can pull it off with -Filter but where-object keeps the queries where they should be.

run("powershell /NoExit Get-WmiObject -class Win32_Product | Where-Object {$_.Name -like '*PowerDirector*'}")

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Thx guys its really to test a theory about modern installshield as they have changed stuff

Ive seen around the web that calling wmi from powershell is the worst way to do things? is this correct?

All im trying to do is uninstall a product from the machine as simply as possible

Share this post


Link to post
Share on other sites

The only thing ever 'happening' is msiexec /x.   How you get the system to that point will not be a contest of best -v- worst, it will be an inane race to shave milliseconds.

 However, there are systems that do not have powershell and likewise systems that do not have WMI.  So if you are unleashing it into the wild, it may not be the most all-encompassing of solutions.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

I agree with boththose (although more on the lack of powershell on a machine than WMI). When I uninstall through WMI I always do a check. You could theoretically branch off from that point; if you can't make the WMI connection try another method:

$sName = InputBox("Uninstall Wizard", "Please type the first few letters of the application name to search")
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")

    If IsObj($oWMI) Then
        $aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'")
        For $app in $aProducts
            $app.Uninstall()
        Next
    Else
        ;Alternate method Branch - walk through Registry or try PS
    EndIf

 


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0