I\'m trying to run a PowerShell command in a batch script. Im trying to remove all traces of an old RMM tool from client PCs and for the life of me can\'t get this line to run c
Check this snippet, it is using WMI but in another way, and has almost never failed me :
function Uninstall-Application($computer, $target) {
$productInfo = Get-WmiObject Win32_Product -Filter "Name LIKE '%$target%'" -ComputerName $computer
$pin = $productInfo.IdentifyingNumber
$pn = $productInfo.Name
$pv = $productInfo.Version
if($pn -ne $null) {
$classKey = "IdentifyingNumber=`"$pin`",Name=`"$pn`",version=`"$pv`""
$uninstallReturn = ([wmi]"\\$computer\root\cimv2:Win32_Product.$classKey").uninstall()
if($uninstallReturn.ReturnValue -ge 0) { Write-Host "Uninstall complete" }
else { $uninstallReturn | Out-Host }
} else {
Throw "Product not found"
}
}
Example usage :
Uninstall-Application "127.0.0.1" "firefox"