Asked by:
Script fails to run

Question
-
$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "7-zip"
}
$app.Uninstall()$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "7-Zip 9.20 (x64 edition)"
}Used this script to delete 7zip from client computer and found no issues. But when I try to run it again got the error:
You cannot call a method on a null-valued expression.
At C:\Scripts\7zip.ps1:2 char:1
+ $app.Uninstall()
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNullMonday, February 24, 2020 10:35 PM
All replies
-
If the installation of the app is not there anymore the command fails. Did you check if 7zip is still installed?
And please format your code as code: How to Use the Code Feature in a TechNet Forum Post When you post error messages or example data you shoud format them as code as well, please.
Live long and prosper!
(79,108,97,102|%{[char]$_})-join''
- Edited by BOfH-666 Monday, February 24, 2020 10:44 PM
Monday, February 24, 2020 10:42 PM -
7Zip is not an installed app. It is an XCOPY app that is xcopied into its folders and separetly items are registeres.
To detect 7Zip just look for it:
Get-Item 'C:\Program Files\7-zip\7z.exe'
If it is on your system this will find it except if you have moved it or changed the install folder.
\_(ツ)_/
Monday, February 24, 2020 10:48 PM -
To uninstall 7-Zip do teh following.
Start-Process 'C:\Program Files\7-zip\Uninstall.exe'
\_(ツ)_/
Monday, February 24, 2020 10:49 PM -
I just noticed that there are MSI versions of this program. They should be removable in your way but the code cannot be run twice in a row.
\_(ツ)_/
Monday, February 24, 2020 10:52 PM