How to remove apps from user context and deploy this script via Intune.

TZ 46 Reputation points
2023-07-20T17:47:21.36+00:00

Hi everyone,

I was trying to remove some apps such as Chrome/Firefox/Zoom and others from many computers in my organization.

These apps were installed manually by the user without admin rights(User Context), I was trying to create a script to remove these apps but it does not work. My intention is to remove all apps installed with no permission, this script will need to be deployed via Intune.

Has anyone got any idea how can I achieve it?

Thanks

T

function Uninstall-Win32App {
    param([string]$appName)
    $uninstallString = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
        Where-Object { $_.DisplayName -like "*$appName*" } |
        Select-Object -ExpandProperty UninstallString

    if ($uninstallString) {
        Write-Output "Uninstalling $appName..."
        Start-Process -FilePath "msiexec.exe" -ArgumentList "/x $uninstallString /quiet" -Wait
    } else {
        Write-Output "$appName not found."
    }
}

# Uninstall Zoom (Win32 application)
Uninstall-Win32App -appName "Zoom"

# Uninstall Chrome (Win32 application)
Uninstall-Win32App -appName "Google Chrome"

# Uninstall Firefox (Win32 application)
Uninstall-Win32App -appName "Mozilla Firefox"


Windows for business Windows Server User experience PowerShell
Microsoft Security Intune Other
{count} votes

Accepted answer
  1. Crystal-MSFT 53,981 Reputation points Microsoft External Staff
    2023-07-26T02:14:21.7933333+00:00

    @TZ, Thanks for the update and sharing. I am glad that the apps can removed successfully. To help others find the method, please let me write a summary:

    Issue:

    How to remove apps from user context via Intune.

    Resolution:

    User's image

    User's image

    User's image

    User's image

    User's image

    Thanks for your time and have a nice day!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. TZ 46 Reputation points
    2023-07-25T08:42:06.31+00:00

    @Crystal-MSFT Thanks for replying. I managed to create the script and remove the apps installed on user-context. The only thing that is not 100% within the script is the Zoom uninstallation process which is not silent, it pops up a window for about 10sec, not a big deal though. I discovered that deploying Zoom via Intune with the System-context setting removes the installation from User-context, and then you can uninstall it via Intune.

    User's image

    Here is the script:

    # Function to uninstall Brave from a specific user profile
    function UninstallBraveFromUserProfile($userProfilePath) {
        $BraveUninstallPath = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
            Where-Object { $_.DisplayName -like "Brave" } |
            Select-Object -ExpandProperty UninstallString -First 1
    
        if ($BraveUninstallPath) {
            Write-Output "Uninstalling Brave from $($userProfilePath)..."
            # Stop any running instances of Brave to avoid conflicts
            Stop-Process -Name Brave -Force -ErrorAction SilentlyContinue
    
            
            # Extract just the path to the Chrome uninstaller
            $BravePathOnly = $BraveUninstallPath.Split(' ')[0]
    
            # Uninstall Brave
            Start-Process -FilePath "$BravePathOnly" -ArgumentList " --uninstall --force-uninstall" -Wait -NoNewWindow
    
    
    
    
            # Check if the uninstallation was successful
            if (Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
                Where-Object { $_.DisplayName -like "Brave" }) {
                Write-Output "Failed to uninstall Brave from $($userProfilePath). Please try again or manually remove it."
            } else {
                Write-Output "Brave successfully uninstalled from $($userProfilePath)."
            }
        } else {
            Write-Output "Brave is not installed in $($userProfilePath)."
        }
    }
    
    # Function to uninstall Google Chrome from a specific user profile
    function UninstallChromeFromUserProfile($userProfilePath) {
        $chromeUninstallPath = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
            Where-Object { $_.DisplayName -like "Google Chrome*" } |
            Select-Object -ExpandProperty UninstallString -First 1
    
        if ($chromeUninstallPath) {
            Write-Output "Uninstalling Google Chrome from $($userProfilePath)..."
            # Stop any running instances of Chrome to avoid conflicts
            Stop-Process -Name chrome -Force -ErrorAction SilentlyContinue
    
            # Extract just the path to the Chrome uninstaller
            $chromePathOnly = $chromeUninstallPath.Split(' ')[0]
    
            # Uninstall Google Chrome
            Start-Process -FilePath "$chromePathOnly" -ArgumentList "--uninstall --force-uninstall" -Wait -NoNewWindow
    
            # Check if the uninstallation was successful
            $chromeUninstallPathAfter = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
                Where-Object { $_.DisplayName -like "Google Chrome*" }
    
            if ($chromeUninstallPathAfter) {
                Write-Output "Failed to uninstall Google Chrome from $($userProfilePath). Please try again or manually remove it."
            } else {
                Write-Output "Google Chrome successfully uninstalled from $($userProfilePath)."
            }
        } else {
            Write-Output "Google Chrome is not installed in $($userProfilePath)."
        }
    }
    
     
    
    # Function to uninstall Mozilla Firefox from a specific user profile
    function UninstallFirefoxFromUserProfile($userProfilePath) {
        $firefoxUninstallPath = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
            Where-Object { $_.DisplayName -like "Mozilla Firefox*" } |
            Select-Object -ExpandProperty UninstallString -First 1
    
        if ($firefoxUninstallPath) {
            Write-Output "Uninstalling Mozilla Firefox from $($userProfilePath)..."
            # Stop any running instances of Firefox to avoid conflicts
            Stop-Process -Name firefox -Force -ErrorAction SilentlyContinue
    
            # Uninstall Mozilla Firefox
            Start-Process -FilePath $firefoxUninstallPath -ArgumentList "/S" -Wait -NoNewWindow
    
            # Check if the uninstallation was successful
            if (Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
                Where-Object { $_.DisplayName -like "Mozilla Firefox*" }) {
                Write-Output "Failed to uninstall Mozilla Firefox from $($userProfilePath). Please try again or manually remove it."
            } else {
                Write-Output "Mozilla Firefox successfully uninstalled from $($userProfilePath)."
            }
        } else {
            Write-Output "Mozilla Firefox is not installed in $($userProfilePath)."
        }
    }
    
     
    
    # Function to uninstall Zoom from a specific user profile
    function UninstallZoomFromUserProfile($userProfilePath) {
        $zoomUninstallPath = Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
            Where-Object { $_.DisplayName -like "Zoom" } |
            Select-Object -ExpandProperty UninstallString -First 1
    
        if ($zoomUninstallPath) {
            Write-Output "Uninstalling Zoom from $($userProfilePath)..."
            # Stop any running instances of Zoom to avoid conflicts
            Stop-Process -Name Zoom -Force -ErrorAction SilentlyContinue
    
            
            # Extract just the path to the Chrome uninstaller
            $zoomPathOnly = $zoomUninstallPath.Split(' ')[0]
    
            # Uninstall Zoom
            Start-Process -FilePath "$zoomPathOnly" -ArgumentList "/uninstall /S" -Wait -NoNewWindow
                    
            # Check if the uninstallation was successful
            if (Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
                Where-Object { $_.DisplayName -like "Zoom" }) {
                Write-Output "Failed to uninstall Zoom from $($userProfilePath). Please try again or manually remove it."
            } else {
                Write-Output "Zoom successfully uninstalled from $($userProfilePath)."
            }
        } else {
            Write-Output "Zoom is not installed in $($userProfilePath)."
        }
    }
    
     
    
    # Get the list of user profiles on the machine
    $userProfiles = Get-ChildItem "C:\Users" -Directory
    
     
    
    # Loop through each user profile and uninstall Google Chrome, Mozilla Firefox, and Zoom
    foreach ($profile in $userProfiles) {
        UninstallBraveFromUserProfile $profile.FullName
        UninstallChromeFromUserProfile $profile.FullName
        UninstallFirefoxFromUserProfile $profile.FullName
        UninstallZoomFromUserProfile $profile.FullName
    }
    

    This is how I deployed via Intune:
    User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.