This folder contains the detection and remediation scripts used to remove McAfee in device context (SYSTEM), including reboot orchestration for locked-file scenarios.
| File | Purpose |
|---|---|
mcafee_detect.ps1 |
Detection script for Intune Proactive Remediations. |
mcafee_remediate.ps1 |
Remediation/uninstall script with cleanup + reboot handling. |
- Returns
1when McAfee is still considered installed:- McAfee uninstall registry traces exist, or
- McAfee file count in known folders is above threshold (
> 10).
- Returns
0when compliant/removed. - Supports reboot marker flow:
- If
C:\ProgramData\Debloat\McAfeeRemoval.reboot.jsonexists and reboot has not occurred yet, detection returns0(temporary compliant state). - If marker is older than 48 hours, detection returns
1to re-trigger remediation. - If reboot happened after marker creation, marker is cleared and normal detection resumes.
- If
- Runs cleanup in SYSTEM context and logs to:
C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\RemoveMcAfee.log
- Downloads cleanup payloads at runtime:
mcafeeclean.zipmccleanup.zip
- Removes registry traces, AppX/provisioned package traces, known folders, and leftover uninstall entries.
- Uses a state model from
Get-McAfeeStatus:0= clean1= installed/significant remnants2= residual + lock scenario
When locked files or reboot-required conditions are detected:
- Remediation schedules reboot at local midnight (
shutdown.exe /r /t <seconds>). - Remediation writes marker:
C:\ProgramData\Debloat\McAfeeRemoval.reboot.json
- Remediation registers one-shot startup task:
- Task name:
McAfeeRemovalPostReboot - Staged script path:
C:\ProgramData\Debloat\mcafee_remediate_postreboot.ps1 - Runs with
-PostReboot - Self-deletes after execution.
- Task name:
- Remediation exits
0so HealthScripts does not record a hard failure while waiting for reboot.
This is intentional to avoid repeated failed remediation runs caused by file locks that only clear after reboot.
The remediation script wraps native tool execution with Invoke-ProcessQuiet:
- Captures child process stdout/stderr to temp files.
- Prevents noisy native stderr (for example, transient access denied during locked-file removal) from surfacing as script stderr in IME.
- Logs relevant events to
RemoveMcAfee.loginstead.
This reduces false failure reporting where remediation logic is successful but external command stderr pollutes HealthScripts result details.
Run as script files (not dot-sourced):
powershell.exe -ExecutionPolicy Bypass -File .\mcafee_detect.ps1
powershell.exe -ExecutionPolicy Bypass -File .\mcafee_remediate.ps1Optional post-reboot mode (normally task-driven):
powershell.exe -ExecutionPolicy Bypass -File .\mcafee_remediate.ps1 -PostReboot- Must run in SYSTEM/device context for full cleanup capability.
- Internet access is required during remediation to fetch cleanup ZIPs from GitHub.
- If network blocks GitHub, cleanup tool download will fail and removal may be incomplete.
- Detection threshold is intentionally conservative (
10files). - If you need to force re-evaluation immediately, remove marker file and rerun detection/remediation.
Primary logs:
C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\RemoveMcAfee.logC:\ProgramData\Microsoft\IntuneManagementExtension\Logs\HealthScripts.log
What to check:
- Final detection state in
RemoveMcAfee.log(clean,residual, orinstalled). - Presence of marker file and startup task when reboot is pending.
- HealthScripts policy result for this script:
FirstDetectExitCodeRemediationExitCodeRemediationStatusRemediationScriptErrorDetails