Intune proactive remediation to Uninstall Software

Remotely Uninstall

Invoke-Command -Computername $Computers {Get-Package -Name "*SilverLight*" | Uninstall-Package}

Locally Uninstall

Get-Package -Name "*SilverLight*" | Uninstall-Package

Location ( Make sure you are licensed to use ) 

Detect

$SoftwareName = "*Silverlight*"

$ItemProperties = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where Displayname -like "*$SoftwareName*"
$ItemProperties32 = Get-ItemProperty "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where Displayname -like "*$SoftwareName*"

if ($ItemProperties -Or $ItemProperties32) {
    Write-Host "$SoftwareName found"
    Exit 1
} Else {
    Write-Host "$SoftwareName Not found"
    Exit 0
}


 catch{
    $errMsg = $_.exeption.essage
    Write-Output $errMsg
 }

Remmediate

# MrNetTek
# eddiejackson.net
# 7/15/2022
# free for public use
# free to claim as your own
 
$SoftwareName = "*Silverlight*"
 
$ItemProperties = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-Object DisplayName,UninstallString
$ItemProperties32 = Get-ItemProperty "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where Displayname -like "*$SoftwareName*"

foreach ($Item in $ItemProperties)
    {
        $DisplayName = $Item.DisplayName
        $UninstallString = $Item.UninstallString
		$PSChildName = $Item.PSChildName
        if($DisplayName -like "*$SoftwareName*")
            {
				Write-Host "MsiExec.exe /X$PSChildname /qn /norestart"
                # Output: Microsoft Silverlight : MsiExec.exe /X{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}
                # We dont use $UninstallString as software Like Forticlient has MsiExec.exe /I ( Install for Uninstall String??? )
                # Always test this on a reference machine, first
                # Sometimes the uninstall string is wrong, right from the vendor
                # If you do run across an invalid uninstall string, fix it
                # and hard code the uninstall string into your script
                # Silverlight was missing the /qn
                cmd.exe /c "MsiExec.exe /X$PSChildname /qn /norestart"
            }
    }
	

foreach ($Item in $ItemProperties32)
    {
        $DisplayName = $Item.DisplayName
        $UninstallString = $Item.UninstallString
		$PSChildName = $Item.PSChildName
        if($DisplayName -like "*$SoftwareName*")
            {
				Write-Host "MsiExec.exe /X$PSChildname /qn /norestart"
                # Output: Microsoft Silverlight : MsiExec.exe /X{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}
                # We dont use $UninstallString as software Like Forticlient has MsiExec.exe /I ( Install for Uninstall String??? )
                # Always test this on a reference machine, first
                # Sometimes the uninstall string is wrong, right from the vendor
                # If you do run across an invalid uninstall string, fix it
                # and hard code the uninstall string into your script
                # Silverlight was missing the /qn
                cmd.exe /c "MsiExec.exe /X$PSChildname /qn /norestart"
            }
    }
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...