Chimaera Posted October 9, 2015 Share Posted October 9, 2015 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 errorPS 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 If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
jvanegmond Posted October 12, 2015 Share Posted October 12, 2015 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. github.com/jvanegmond Link to comment Share on other sites More sharing options...
iamtheky Posted October 12, 2015 Share Posted October 12, 2015 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*'}") ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Chimaera Posted October 13, 2015 Author Share Posted October 13, 2015 Thx guys its really to test a theory about modern installshield as they have changed stuffIve 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 If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
iamtheky Posted October 13, 2015 Share Posted October 13, 2015 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. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 13, 2015 Moderators Share Posted October 13, 2015 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 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Chimaera Posted October 14, 2015 Author Share Posted October 14, 2015 ok thanks for the help If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now