Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save travisterrell/ced8108e8ca8294b3c6e5c5deac9a87d to your computer and use it in GitHub Desktop.
Save travisterrell/ced8108e8ca8294b3c6e5c5deac9a87d to your computer and use it in GitHub Desktop.
Adds Windows Defender exclusions for Visual Studio 2019
$userPath = $env:USERPROFILE
$pathExclusions = New-Object System.Collections.ArrayList
$processExclusions = New-Object System.Collections.ArrayList
$pathExclusions.Add('C:\Windows\Microsoft.NET') > $null
$pathExclusions.Add('C:\Windows\assembly') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio Services') > $null
$pathExclusions.Add($userPath + '\AppData\Local\GitCredentialManager') > $null
$pathExclusions.Add($userPath + '\AppData\Local\GitHubVisualStudio') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\dotnet') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VSApplicationInsights') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VSCommon') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\Microsoft\VisualStudio') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\NuGet') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\Visual Studio Setup') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\vstelemetry') > $null
$pathExclusions.Add($userPath + '\AppData\Roaming\Microsoft\VisualStudio') > $null
$pathExclusions.Add($userPath + '\.dotnet') > $null
$pathExclusions.Add($userPath + '\.librarymanager') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Temp\VSFeedbackIntelliCodeLogs') > $null
$pathExclusions.Add('C:\ProgramData\Microsoft\VisualStudio') > $null
$pathExclusions.Add('C:\ProgramData\Microsoft\NetFramework') > $null
$pathExclusions.Add('C:\ProgramData\Microsoft Visual Studio') > $null
$pathExclusions.Add('C:\Program Files (x86)\MSBuild') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio') > $null
$pathExclusions.Add('C:\Program Files\dotnet') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SDKs\NuGetPackages') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SDKs\TypeScript') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SDKs') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SQL Server') > $null
$pathExclusions.Add('C:\Program Files\Microsoft SQL Server') > $null
$pathExclusions.Add('C:\Program Files (x86)\Entity Framework Tools') > $null
$pathExclusions.Add('C:\Program Files (x86)\IIS') > $null
$pathExclusions.Add('C:\Program Files (x86)\IIS Express') > $null
$pathExclusions.Add('C:\Program Files\IIS') > $null
$pathExclusions.Add('C:\Program Files\IIS Express') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft Web Tools') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft.NET') > $null
$pathExclusions.Add('C:\Program Files (x86)\MySQL') > $null
$pathExclusions.Add('C:\Program Files\MySQL') > $null
$pathExclusions.Add('C:\ProgramData\MySQL') > $null
$pathExclusions.Add('C:\Program Files (x86)\NuGet') > $null
$pathExclusions.Add('C:\Program Files\Git') > $null
$pathExclusions.Add('C:\ProgramData\Git') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\devenv.exe') > $null
$processExclusions.Add('C:\Program Files\dotnet\dotnet.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\JetBrains\JetBrains Rider 2020.3.2\lib\ReSharperHost\windows-x64\dotnet\dotnet.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\JetBrains\JetBrains Rider 2020.3.2\tools\MSBuild\Current\Bin\amd64\MSBuild.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\JetBrains\JetBrains Rider 2020.3.2\tools\MSBuild\Current\Bin\ref\MSBuild.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\JetBrains\JetBrains Rider 2020.3.2\tools\MSBuild\Current\Bin\MSBuild.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\MSBuild.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\NodeJs\node.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\NodeJs\win-x64\node.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\NodeJs\node.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio\NodeJs\win-x64\node.exe') > $null
# SO many git paths on my system, plus I want code downloaded from github/etc. to be scanned
# $processExclusions.Add('git.exe') > $null
# 32 separate paths to node.js files and I don't do a lot of node development - Skipping for now
# $processExclusions.Add('node.js') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PerfWatson2.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\PerfWatson2.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\ServiceHub\Hosts\ServiceHub.Host.Node.x86\ServiceHub.Host.Node.x86.exe') > $null
$processExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\ServiceHub\Hosts\ServiceHub.Host.Node.x86\ServiceHub.Host.Node.x86.exe') > $null
# Build cache
# $processExclusions.Add('vbcscompiler.exe') > $null
Write-Host "This script will create Windows Defender exclusions for common Visual Studio 2019 folders and processes."
Write-Host ""
$projectsFolder = Read-Host 'What is the path to your Projects folder? (example: C:\Projects)'
Write-Host ""
Write-Host "Adding Path Exclusion: " $projectsFolder
Add-MpPreference -ExclusionPath $projectsFolder
foreach ($exclusion in $pathExclusions)
{
Write-Host "Adding Path Exclusion: " $exclusion
Add-MpPreference -ExclusionPath $exclusion
}
foreach ($exclusion in $processExclusions)
{
Write-Host "Adding Process Exclusion: " $exclusion
Add-MpPreference -ExclusionProcess $exclusion
}
Write-Host ""
Write-Host "Your Exclusions:"
$prefs = Get-MpPreference
$prefs.ExclusionPath
$prefs.ExclusionProcess
Write-Host ""
Write-Host "Enjoy faster build times and coding!"
Write-Host ""
@travisterrell
Copy link
Author

travisterrell commented Jan 26, 2021

This fork updates the process exclusions to use absolute paths for increased security, as well as remove a few exclusions (for 3rd party programs I do not use, git (for now), and node.js*

*There were an absurd number of paths to this on my system, and not sure which are used (I rarely code in Node).

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