Skip to content

Instantly share code, notes, and snippets.

@gschizas
Last active March 6, 2022 06:53
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gschizas/94f432c68944dfc53414bb4cc7f7a2bb to your computer and use it in GitHub Desktop.
Save gschizas/94f432c68944dfc53414bb4cc7f7a2bb to your computer and use it in GitHub Desktop.
Allow all blocked apps to Windows Defender's Controlled folder access (interactively)
$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 $_
}
@grrunnz
Copy link

grrunnz commented May 16, 2018

On my PC the id for the events changed from 1123 to 1127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment