Forked from Braytiner/Windows Defender Exclusions VS 2022.ps1
Last active
November 21, 2022 13:20
-
-
Save jhochwald/dcf68089c0a79f298358accbd92501de to your computer and use it in GitHub Desktop.
Adds Windows Defender exclusions for Visual Studio 2022
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
$pathExclusions = (New-Object -TypeName System.Collections.ArrayList) | |
$processExclusions = (New-Object -TypeName System.Collections.ArrayList) | |
$null = $pathExclusions.Add($env:windir + '\Microsoft.NET') | |
$null = $pathExclusions.Add($env:windir + '\assembly') | |
#$null = $pathExclusions.Add($env:USERPROFILE + '\Downloads\HeidiSQL_11.3_64_Portable') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.dotnet') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.nuget') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.vscode') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.ssh') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.apricotdb') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.dbgate') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.rest-client') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\.librarymanager') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\Microsoft\VisualStudio') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\Microsoft\VisualStudio Services') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\GitCredentialManager') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\GitHubVisualStudio') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\Microsoft\dotnet') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\Microsoft\VSApplicationInsights') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\Microsoft\VSCommon') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Local\Temp\VSFeedbackIntelliCodeLogs') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Roaming\Microsoft\VisualStudio') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Roaming\NuGet') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Roaming\Visual Studio Setup') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Roaming\vstelemetry') | |
$null = $pathExclusions.Add($env:USERPROFILE + '\AppData\Roaming\HeidiSQL') | |
$null = $pathExclusions.Add($env:ProgramData + '\Microsoft\VisualStudio') | |
$null = $pathExclusions.Add($env:ProgramData + '\Microsoft\NetFramework') | |
$null = $pathExclusions.Add($env:ProgramData + '\Microsoft Visual Studio') | |
$null = $pathExclusions.Add($env:ProgramData + '\MySQL') | |
$null = $pathExclusions.Add($env:ProgramW6432 + '\Microsoft Visual Studio') | |
$null = $pathExclusions.Add($env:ProgramW6432 + '\dotnet') | |
$null = $pathExclusions.Add($env:ProgramW6432 + '\Microsoft SDKs') | |
$null = $pathExclusions.Add($env:ProgramW6432 + '\Microsoft SQL Server') | |
$null = $pathExclusions.Add($env:ProgramW6432 + '\MySQL') | |
$null = $pathExclusions.Add($env:ProgramW6432 + '\IIS') | |
$null = $pathExclusions.Add($env:ProgramW6432 + '\IIS Express') | |
$null = $pathExclusions.Add(${Env:ProgramFiles} + '\Git\cmd\git.exe') | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + '\Microsoft Visual Studio') | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + '\dotnet') | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + '\Microsoft SDKs') | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + '\Microsoft SQL Server') | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + '\IIS') | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + '\IIS Express') | |
# Cache directories | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + "\Microsoft Visual Studio") | |
$null = $pathExclusions.Add($env:windir + "\assembly") | |
$null = $pathExclusions.Add($env:windir + "\Microsoft.NET") | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + "\MSBuild") | |
$null = $pathExclusions.Add($env:ProgramW6432 + "\dotnet") | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + "\Microsoft SDKs") | |
$null = $pathExclusions.Add($env:ProgramW6432 + "\Microsoft SDKs") | |
$null = $pathExclusions.Add(${env:CommonProgramFiles(x86)} + "\Microsoft Shared\MSEnv") | |
$null = $pathExclusions.Add($env:ProgramData + "\Microsoft\VisualStudio\Packages") | |
$null = $pathExclusions.Add(${env:ProgramFiles(x86)} + "\Microsoft SDKs\NuGetPackages") | |
$null = $pathExclusions.Add($env:windir + "\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files") | |
$null = $pathExclusions.Add($env:windir + "\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files") | |
$null = $pathExclusions.Add($env:HOMEDRIVE + "\Users\Administrator\AppData\Local\Microsoft\WebsiteCache") | |
$null = $pathExclusions.Add($env:HOMEDRIVE + "\Users\Administrator\AppData\Roaming\Microsoft\VisualStudio") | |
$null = $pathExclusions.Add($Env:USERPROFILE + "\AppData\Local\Microsoft\VisualStudio") | |
$null = $pathExclusions.Add($Env:USERPROFILE + "\AppData\Local\Microsoft\WebsiteCache") | |
$null = $pathExclusions.Add($Env:USERPROFILE + "\AppData\Roaming\Microsoft\VisualStudio") | |
$null = $processExclusions.Add("Microsoft.ServiceHub.Controller.exe") | |
$null = $processExclusions.Add("ServiceHub.DataWarehouseHost.exe") | |
$null = $processExclusions.Add("ServiceHub.Host.CLR.exe") | |
$null = $processExclusions.Add("ServiceHub.Host.CLR.x64.exe") | |
$null = $processExclusions.Add("ServiceHub.Host.CLR.x86.exe") | |
$null = $processExclusions.Add("ServiceHub.Host.Node.x86.exe") | |
$null = $processExclusions.Add("ServiceHub.IdentityHost.exe") | |
$null = $processExclusions.Add("ServiceHub.IndexingService.exe") | |
$null = $processExclusions.Add("ServiceHub.RoslynCodeAnalysisService.exe") | |
$null = $processExclusions.Add("ServiceHub.SettingsHost.exe") | |
$null = $processExclusions.Add("ServiceHub.TestWindowStoreHost.exe") | |
$null = $processExclusions.Add("ServiceHub.ThreadedWaitDialog.exe") | |
$null = $processExclusions.Add("ServiceHub.VSDetouredHost.exe") | |
$null = $processExclusions.Add("vstest.console.exe") | |
$null = $processExclusions.Add("Microsoft.VisualStudio.Web.Host.exe") | |
$null = $processExclusions.Add("Microsoft.WebTools.Languages.LanguageServer.Host.exe") | |
$null = $processExclusions.Add("node.exe") | |
$null = $processExclusions.Add("deno.exe") | |
$null = $processExclusions.Add("PerfWatson2.exe") | |
$null = $processExclusions.Add("sqlwriter.exe") | |
$null = $processExclusions.Add("sqlservr.exe") | |
$null = $processExclusions.Add("com.docker.service.exe") | |
$null = $processExclusions.Add("dotnet.exe") | |
$null = $processExclusions.Add("Code.exe") | |
$null = $processExclusions.Add("gpg-agent.exe") | |
$null = $processExclusions.Add("gpg-connect-agent.exe") | |
$null = $processExclusions.Add("ssh-agent.exe") | |
$null = $processExclusions.Add("vsls-agent.exe") | |
$null = $processExclusions.Add("iisexpress.exe") | |
$null = $processExclusions.Add("nvm.exe") | |
$null = $processExclusions.Add("wsl.exe") | |
$null = $processExclusions.Add(${Env:ProgramFiles} + '\Git\cmd\git.exe') | |
$null = $processExclusions.Add($env:windir + '\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe') | |
$null = $processExclusions.Add($env:windir + '\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe') | |
$null = $processExclusions.Add(${env:ProgramFiles(x86)} + '\MSBuild\14.0\Bin\MSBuild.exe') | |
$null = $processExclusions.Add($env:ProgramW6432 + '\dotnet\dotnet.exe') | |
Write-Output -InputObject 'This script will create Windows Defender exclusions for common Visual Studio 2022 folders and processes.' | |
Write-Output -InputObject '' | |
$projectsFolder = Read-Host -Prompt 'What is the path to your Projects folder? (example: c:\source)' | |
Write-Output -InputObject '' | |
Write-Output -InputObject 'Adding Path Exclusion: ', $projectsFolder | |
Add-MpPreference -ExclusionPath $projectsFolder | |
foreach ($exclusion in $pathExclusions) | |
{ | |
Write-Output -InputObject ('Adding Path Exclusion: {0}' -f $exclusion) | |
Add-MpPreference -ExclusionPath $exclusion -Force -ErrorAction Continue | |
} | |
foreach ($exclusion in $processExclusions) | |
{ | |
Write-Output -InputObject ('Adding Process Exclusion: {0}' -f $exclusion) | |
Add-MpPreference -ExclusionProcess $exclusion -Force -ErrorAction Continue | |
} | |
Write-Output -InputObject '' | |
Write-Output -InputObject 'Your Exclusions:' | |
$prefs = Get-MpPreference | |
$prefs.ExclusionPath | |
$prefs.ExclusionProcess | |
Write-Output -InputObject '' | |
Write-Output -InputObject 'Enjoy faster build times and coding!' | |
Write-Output -InputObject '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment