Last active
December 1, 2024 14:28
-
-
Save gschizas/94f432c68944dfc53414bb4cc7f7a2bb to your computer and use it in GitHub Desktop.
Allow all blocked apps to Windows Defender's Controlled folder access (interactively)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$appEvents = Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" | | |
Where-Object {$_.Id -eq "1123"} | |
$allBlockedProcesses = ( | |
$appEvents | | |
ForEach-Object { | |
(([xml]$_.ToXml()).Event.EventData.Data | | |
Where-Object { | |
$_.Name -eq "Process Name" | |
}).'#text' | |
} | | |
Sort-Object -Unique | |
) | |
$currentWhiteList = (Get-MpPreference).ControlledFolderAccessAllowedApplications | |
if ($allBlockedProcesses -eq $null) { | |
Write-Host -ForegroundColor Red "No Processes have been filtered" | |
exit 3 | |
} | |
if ($currentWhiteList -eq $null) { | |
$newProcesses = $allBlockedProcesses | |
} | |
else { | |
$newProcesses = Compare-Object ` | |
-ReferenceObject $allBlockedProcesses ` | |
-DifferenceObject $currentWhiteList | | |
Where-Object { | |
$_.SideIndicator -eq '<=' | |
} | | |
Select-Object -ExpandProperty InputObject | |
} | |
if ($newProcesses -eq $null) { | |
Write-Host -ForegroundColor Green "All processes have already been added" | |
exit 0 | |
} | |
$newProcesses | | |
Out-GridView -PassThru | | |
ForEach-Object { | |
Add-MpPreference -ControlledFolderAccessAllowedApplications $_ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On my PC the id for the events changed from 1123 to 1127