Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save giggio/86c2ad9c7cec8ab4e09727e9d9fa7605 to your computer and use it in GitHub Desktop.
Save giggio/86c2ad9c7cec8ab4e09727e9d9fa7605 to your computer and use it in GitHub Desktop.
Adds Windows Defender exclusions for developers (Visual Studio, JetBrains Rider, IntellIJ Idea, Git, MsBuild, dotnet, mono etc.)
[cmdletbinding()]
Param()
$ErrorActionPreference = "Stop"
$pathExclusions = New-Object System.Collections.ArrayList
$processExclusions = New-Object System.Collections.ArrayList
$programFilesX86 = ${env:ProgramFiles(x86)}
if ($null -eq $programFilesX86) {
$programFilesX86 = $env:ProgramFiles
}
$programFiles = $env:ProgramFiles
function Add-ProcessExclusion($processName) {
if (Test-Path $processName) {
$fullProcessLocation = $processName
} else {
$command = Get-Command $processName -ErrorAction SilentlyContinue
if ($null -eq $command) {
Write-Warning "Could not find command for process '$processName'."
return
}
if ($command.CommandType -ne 'Application') {
Write-Warning "Command '$processName' is not an application."
return
}
$fullProcessLocation = $command.Source
}
if ($null -ne $fullProcessLocation) {
$processExclusions.Add($fullProcessLocation) > $null
} else {
Write-Warning "Could not find path for process '$processName'."
}
}
function Add-PathExclusion($path) {
if (Test-Path $path) {
$pathExclusions.Add($path) > $null
} else {
Write-Warning "Could not find path '$path'."
}
}
# paths
Add-PathExclusion "$env:WINDIR\Microsoft.NET"
Add-PathExclusion "$env:WINDIR\assembly"
Add-PathExclusion "$env:WINDIR\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files"
Add-PathExclusion "$env:WINDIR\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files"
Add-PathExclusion "$env:ProgramData\Microsoft\VisualStudio\Packages"
Add-PathExclusion "$env:ProgramData\Docker"
Add-PathExclusion "$programFilesX86\MSBuild"
Add-PathExclusion "$programFilesX86\Microsoft Visual Studio"
Add-PathExclusion "$programFiles\Microsoft Visual Studio"
Add-PathExclusion "$programFilesX86\Microsoft Visual Studio"
Add-PathExclusion "$programFilesX86\Microsoft SDKs\NuGetPackages"
Add-PathExclusion "$programFilesX86\Microsoft SDKs"
Add-PathExclusion "$programFilesX86\Common Files\Microsoft Shared\MSEnv"
Add-PathExclusion "$programFiles\dotnet"
Add-PathExclusion "$programFiles\Microsoft SDKs"
Add-PathExclusion "$env:APPDATA\Microsoft\VisualStudio"
Add-PathExclusion "$env:APPDATA\NuGet"
Add-PathExclusion "$env:APPDATA\Microsoft\VisualStudio"
Add-PathExclusion "$env:LOCALAPPDATA\Docker"
Add-PathExclusion "$env:LOCALAPPDATA\npm-cache"
Add-PathExclusion "$env:LOCALAPPDATA\Microsoft\WebsiteCache"
Add-PathExclusion "$env:LOCALAPPDATA\Microsoft\dotnet"
Add-PathExclusion "$env:LOCALAPPDATA\Microsoft\VSApplicationInsights"
Add-PathExclusion "$env:LOCALAPPDATA\Microsoft\VSCommon"
Add-PathExclusion "$env:LOCALAPPDATA\Microsoft\VisualStudio"
Add-PathExclusion "$env:LOCALAPPDATA\Packages\36828agowa338.AlpineWSL_my43bytk1c4nr"
Add-PathExclusion "$env:LOCALAPPDATA\Packages\46932SUSE.openSUSELeap42.2_022rs5jcyhyac"
Add-PathExclusion "$env:LOCALAPPDATA\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc"
Add-PathExclusion "$env:USERPROFILE\.dotnet"
Add-PathExclusion "$env:USERPROFILE\scoop"
Add-PathExclusion "$env:USERPROFILE\.nuget"
# my local paths, update to yours
Add-PathExclusion "c:\p"
Add-PathExclusion "c:\vms"
# processes
Add-ProcessExclusion "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe"
Add-ProcessExclusion "$programFiles\Docker\Docker\resources\dockerd.exe"
Add-ProcessExclusion "$programFiles\Docker\Docker\resources\bin\docker.exe"
Add-ProcessExclusion "$programFiles\Docker\Docker\Docker Desktop.exe"
Add-ProcessExclusion "dotnet.exe"
Add-ProcessExclusion "msbuild.exe"
Add-ProcessExclusion "node.exe"
Add-ProcessExclusion "perfwatson2.exe"
Add-ProcessExclusion "$programFiles\Microsoft Visual Studio\2022\Enterprise\Common7\ServiceHub\Hosts\ServiceHub.Host.Node.x86\ServiceHub.Host.Node.x86.exe"
Add-ProcessExclusion "vbcscompiler.exe"
Add-ProcessExclusion "nuget.exe"
Add-ProcessExclusion "git.exe"
Add-ProcessExclusion "vshost-clr2.exe"
Add-ProcessExclusion "VSInitializer.exe"
Add-ProcessExclusion "VSLaunchBrowser.exe"
Add-ProcessExclusion "devenv.exe"
Add-ProcessExclusion "Microsoft.VisualStudio.Web.Host.exe"
Add-ProcessExclusion "MSTest.exe"
Add-ProcessExclusion "vshost.exe"
Add-ProcessExclusion "vshost32.exe"
Add-ProcessExclusion "vshost32-clr2.exe"
Write-Host "This script will create Windows Defender exclusions for common development folders and processes."
$currentPreferences = Get-MpPreference
foreach ($exclusion in $pathExclusions) {
if ($currentPreferences.ExclusionPath -notcontains $exclusion) {
Write-Host "Adding Path Exclusion: " $exclusion
Add-MpPreference -ExclusionPath $exclusion
} else {
Write-Verbose "Path Exclusion already exists: $exclusion"
}
}
foreach ($exclusion in $processExclusions) {
if ($currentPreferences.ExclusionProcess -notcontains $exclusion) {
Write-Host "Adding Process Exclusion: " $exclusion
Add-MpPreference -ExclusionProcess $exclusion
} else {
Write-Verbose "Process Exclusion already exists: $exclusion"
}
}
Write-Verbose "Exclusion status after update."
$updatedPrefs = Get-MpPreference
Write-Verbose "Paths:$($updatedPrefs.ExclusionPath | ForEach-Object { "`n$_" })"
Write-Verbose "Processes:$($updatedPrefs.ExclusionProcess | ForEach-Object { "`n$_" })"
Write-Verbose Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment