Removing Windows Store Apps

This is a constant issue when trying to achieve vulnerability compliance, so how can we complete this more efficiently?

The script below will take your application, which you name in line 2 in the $appName available. It will attempt to utilise multiple removal methods to eliminate this app from users on your system and provisioned packages. Please go ahead and run this as an administrator.

This script will take a pre-defined app from $appName and will remove it. 

This script will ask you for the app (or partial name), find it, and ask if you want it removed

 

# Define the app to remove (case-insensitive partial name match)
$appName = "Microsoft.GamingApp"  # Change this to the app name you want to remove

# Create a log file for tracking results
$logFile = "C:\Temp\AppRemovalLog.txt"
if (-not (Test-Path (Split-Path -Path $logFile -Parent))) {
    New-Item -ItemType Directory -Path (Split-Path -Path $logFile -Parent) | Out-Null
}
"Starting removal process for app: $appName" | Out-File -Append $logFile

# Function to log messages
function Write-Log {
    param([string]$message)
    $time = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    "$time - $message" | Out-File -Append $logFile
    Write-Output "$time - $message"
}

# Step 1: Remove AppxPackage (current user)
Write-Log "Attempting to remove AppxPackage for current user..."
try {
    Get-AppxPackage -AllUsers -Name "*$appName*" | ForEach-Object {
        Write-Log "Found package: $($_.Name) - Removing..."
        Remove-AppxPackage -Package $_.PackageFullName -AllUsers -ErrorAction Continue
    }
} catch {
    Write-Log "Error removing AppxPackage: $_"
}

# Step 2: Remove AppxProvisionedPackage (provisioned for new users)
Write-Log "Attempting to remove AppxProvisionedPackage for all users..."
try {
    Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -like "*$appName*" } | ForEach-Object {
        Write-Log "Found provisioned package: $($_.DisplayName) - Removing..."
        Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName -ErrorAction Continue
    }
} catch {
    Write-Log "Error removing AppxProvisionedPackage: $_"
}

# Step 3: Search registry for uninstall commands
Write-Log "Attempting to find and execute uninstall commands from registry..."
$regPaths = @(
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
    "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
    "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
)

foreach ($path in $regPaths) {
    try {
        Get-ChildItem -Path $path -ErrorAction SilentlyContinue | ForEach-Object {
            $displayName = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).DisplayName
            $uninstallString = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).UninstallString

            if ($displayName -and $displayName -like "*$appName*") {
                Write-Log "Registry found app: $displayName"
                if ($uninstallString) {
                    Write-Log "Executing uninstall command: $uninstallString"
                    Start-Process "cmd.exe" -ArgumentList "/c $uninstallString /quiet /norestart" -Wait -ErrorAction Continue
                } else {
                    Write-Log "No uninstall string found for $displayName"
                }
            }
        }
    } catch {
        Write-Log "Error searching registry: $_"
    }
}

# Step 4: Force-remove app via DISM if applicable
Write-Log "Attempting to remove package using DISM..."
try {
    $dismOutput = dism /online /get-packages
    $targetPackage = ($dismOutput | Select-String -Pattern $appName).Line
    if ($targetPackage) {
        $packageName = ($targetPackage -split ":")[1].Trim()
        Write-Log "Found package: $packageName - Removing with DISM..."
        Start-Process "dism.exe" -ArgumentList "/online", "/remove-package", "/packagename:$packageName", "/norestart" -Wait
    } else {
        Write-Log "No matching package found via DISM."
    }
} catch {
    Write-Log "Error removing package with DISM: $_"
}

# Final log entry
Write-Log "Removal process completed for app: $appName"

 

SCRIPT TO ASK WHAT APP YOU WANT TO REMOVE

# Define a log file for tracking results
$logFile = "C:\Temp\AppRemovalLog.txt"
if (-not (Test-Path (Split-Path -Path $logFile -Parent))) {
    New-Item -ItemType Directory -Path (Split-Path -Path $logFile -Parent) | Out-Null
}
"Starting application removal process..." | Out-File -Append $logFile

# Function to log messages
function Write-Log {
    param([string]$message)
    $time = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    "$time - $message" | Out-File -Append $logFile
    Write-Output "$time - $message"
}

# Prompt user for app name
$appName = Read-Host "Enter the partial or full name of the application you want to remove"

# Search for matching apps
Write-Log "Searching for applications matching: $appName"
$appFound = $false
$appMatches = @()

# Define registry paths to search for uninstall commands
$regPaths = @(
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
    "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
    "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
)

# Search through registry paths
foreach ($path in $regPaths) {
    Get-ChildItem -Path $path -ErrorAction SilentlyContinue | ForEach-Object {
        $displayName = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).DisplayName
        if ($displayName -and $displayName -like "*$appName*") {
            $appMatches += $displayName
        }
    }
}

# Search AppxPackages as well
$appxPackages = Get-AppxPackage -AllUsers | Where-Object { $_.Name -like "*$appName*" }
foreach ($pkg in $appxPackages) {
    $appMatches += $pkg.Name
}

# Display found apps
if ($appMatches.Count -eq 0) {
    Write-Output "No applications found matching '$appName'."
    exit
}

Write-Output "Found the following applications:"
$appMatches | ForEach-Object { Write-Output "- $_" }

# Ask user to confirm removal
$response = Read-Host "Do you want to proceed with removing these applications? (yes/no)"
if ($response -ne 'yes') {
    Write-Output "Operation cancelled by the user."
    exit
}

# Proceed with removal
foreach ($match in $appMatches) {
    Write-Log "Starting removal process for app: $match"

    # Step 1: Remove AppxPackage (current user)
    Write-Log "Attempting to remove AppxPackage for current user..."
    try {
        Get-AppxPackage -AllUsers -Name "*$match*" | ForEach-Object {
            Write-Log "Found package: $($_.Name) - Removing..."
            Remove-AppxPackage -Package $_.PackageFullName -AllUsers -ErrorAction Continue
        }
    } catch {
        Write-Log "Error removing AppxPackage: $_"
    }

    # Step 2: Remove AppxProvisionedPackage (provisioned for new users)
    Write-Log "Attempting to remove AppxProvisionedPackage for all users..."
    try {
        Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -like "*$match*" } | ForEach-Object {
            Write-Log "Found provisioned package: $($_.DisplayName) - Removing..."
            Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName -ErrorAction Continue
        }
    } catch {
        Write-Log "Error removing AppxProvisionedPackage: $_"
    }

    # Step 3: Search registry for uninstall commands
    Write-Log "Attempting to find and execute uninstall commands from registry..."
    foreach ($path in $regPaths) {
        try {
            Get-ChildItem -Path $path -ErrorAction SilentlyContinue | ForEach-Object {
                $displayName = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).DisplayName
                $uninstallString = (Get-ItemProperty -Path $_.PSPath -ErrorAction SilentlyContinue).UninstallString

                if ($displayName -and $displayName -like "*$match*") {
                    Write-Log "Registry found app: $displayName"
                    if ($uninstallString) {
                        Write-Log "Executing uninstall command: $uninstallString"
                        Start-Process "cmd.exe" -ArgumentList "/c $uninstallString /quiet /norestart" -Wait -ErrorAction Continue
                    } else {
                        Write-Log "No uninstall string found for $displayName"
                    }
                }
            }
        } catch {
            Write-Log "Error searching registry: $_"
        }
    }

    # Step 4: Force-remove app via DISM if applicable
    Write-Log "Attempting to remove package using DISM..."
    try {
        $dismOutput = dism /online /get-packages
        $targetPackage = ($dismOutput | Select-String -Pattern $match).Line
        if ($targetPackage) {
            $packageName = ($targetPackage -split ":")[1].Trim()
            Write-Log "Found package: $packageName - Removing with DISM..."
            Start-Process "dism.exe" -ArgumentList "/online", "/remove-package", "/packagename:$packageName", "/norestart" -Wait
        } else {
            Write-Log "No matching package found via DISM."
        }
    } catch {
        Write-Log "Error removing package with DISM: $_"
    }

    # Final log entry
    Write-Log "Removal process completed for app: $match"
}

Write-Log "All requested applications processed."