Remediate-AppHealth.ps1

<#PSScriptInfo
.VERSION 1.1
.GUID f9b1c4e2-7d3a-4a0c-8f55-2c7e9a1b3d77
.AUTHOR Mert Efe Kanlikilic
.DESCRIPTION A remediation script that resolves common application health issues on Intune-managed Windows devices.
#>


$logPath = "C:\ProgramData\IntuneRemediations\AppHealth.log"

function Write-Log {
    param ($msg)
    $time = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

    $logDir = Split-Path $logPath
    if (!(Test-Path $logDir)) {
        New-Item -ItemType Directory -Path $logDir -Force | Out-Null
    }

    Add-Content -Path $logPath -Value "$time - $msg"
    Write-Output $msg
}

try {
    Write-Log "App health remediation triggered"

    Write-Log "Restarting Intune Management Extension service"

    Restart-Service IntuneManagementExtension -Force -ErrorAction Stop

    Start-Sleep -Seconds 10

    Write-Log "IME restarted successfully - app re-evaluation should begin"

    exit 0
}
catch {
    Write-Log "Remediation failed: $_"
    exit 1
}