Last active
October 11, 2024 15:43
-
-
Save dknoodle/959d6e9d399e51cc28957f85d4b4417f to your computer and use it in GitHub Desktop.
Windows Defender exclusions for Visual Studio development
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
# Function to display colored text | |
function Write-ColorOutput($ForegroundColor) | |
{ | |
$fc = $host.UI.RawUI.ForegroundColor | |
$host.UI.RawUI.ForegroundColor = $ForegroundColor | |
if ($args) { | |
Write-Output $args | |
} | |
else { | |
$input | Write-Output | |
} | |
$host.UI.RawUI.ForegroundColor = $fc | |
} | |
# Display developer-friendly disclaimer | |
Write-ColorOutput Cyan @" | |
Hey there, Developer! 👋 | |
Before we dive into optimizing your system for development, let's have a quick chat about what this script does and what it means for you. We want to make sure we're on the same page, so please read through this carefully. | |
What This Script Does: | |
This script adds exclusions to Windows Defender for common development tools and folders. It's designed to speed up your development workflow by reducing unnecessary scans. | |
The Not-So-Fun (But Important) Legal Bits: | |
1. 🛠 Use As-Is: This script is provided as-is, without any warranties. It's like that experimental library you found on GitHub - it might be awesome, but there are no guarantees. | |
2. 🎲 Your Call, Your Responsibility: By running this script, you're taking on the risk. If something goes sideways, it's on you, not us. Think of it like deploying to production - you've tested it, but ultimately, you're the one pushing the button. | |
3. 🛡 Security Implications: This script modifies your security settings. It's like leaving your development door unlocked - it's easier to get in and out, but someone else might sneak in too. | |
4. 🤝 Don't Shoot the Messenger: If things go wrong, please don't come after us legally. We're just trying to help the developer community, not get into legal battles. | |
5. 🌎 Universal Rules Apply: Depending on where you are, different laws might apply, but the general gist is: you're responsible for what happens when you run this script. | |
The Bottom Line: | |
By using this script, you're acknowledging that you understand the risks involved in modifying your system's security settings. You're also agreeing not to hold the script's creators or distributors liable for any issues that might arise. | |
Remember, with great power comes great responsibility. Use this script wisely, and always keep your developer spidey-senses tuned for any unusual system behavior. | |
Ready to supercharge your dev environment? Let's do this! 🚀 | |
"@ | |
# Prompt for agreement | |
$agreement = Read-Host "If you've read and understood the above, type 'I UNDERSTAND' (in all caps) to proceed" | |
if ($agreement -ne "I UNDERSTAND") { | |
Write-ColorOutput Yellow "No worries! The script will exit without making any changes. Stay safe out there!" | |
exit | |
} | |
# Display warning message | |
Write-ColorOutput Red @" | |
FINAL WARNING: SECURITY MODIFICATION AHEAD | |
This script is about to add exclusions to Windows Defender for various development tools and folders. | |
This action could potentially expose your computer to security risks if it's compromised. | |
Only proceed if: | |
1. You fully understand the implications | |
2. You're using this on a dedicated development machine | |
3. You're comfortable managing the additional security risks | |
To proceed, please type 'YES' (in all caps) and press Enter. | |
To cancel, press Enter without typing 'YES' or close this window. | |
"@ | |
$confirmation = Read-Host "Are you ready to proceed?" | |
if ($confirmation -ne "YES") { | |
Write-ColorOutput Yellow "Operation cancelled. Your system remains unchanged. Happy coding!" | |
exit | |
} | |
$userPath = $env:USERPROFILE | |
$pathExclusions = New-Object System.Collections.ArrayList | |
$processExclusions = New-Object System.Collections.ArrayList | |
# Path exclusions | |
$pathExclusions.Add('C:\Windows\Microsoft.NET') > $null | |
$pathExclusions.Add('C:\Windows\assembly') > $null | |
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio') > $null | |
$pathExclusions.Add('C:\ProgramData\Microsoft\VisualStudio\Packages') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\MSBuild') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SDKs\NuGetPackages') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SDKs') > $null | |
$pathExclusions.Add('C:\Program Files\Microsoft Visual Studio\2022') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio\2022') > $null | |
$pathExclusions.Add('C:\Program Files\dotnet') > $null | |
$pathExclusions.Add($userPath + '\.dotnet') > $null | |
$pathExclusions.Add($userPath + '\.nuget') > $null | |
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio\Packages') > $null | |
$pathExclusions.Add($userPath + '\.vs-kubernetes') > $null | |
$pathExclusions.Add('C:\Program Files\Git') > $null | |
$pathExclusions.Add('C:\Program Files\Docker') > $null | |
$pathExclusions.Add('C:\Program Files\nodejs') > $null | |
$pathExclusions.Add($userPath + '\AppData\Roaming\npm') > $null | |
$pathExclusions.Add('C:\Python*') > $null | |
$pathExclusions.Add('C:\Program Files\Java') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\Java') > $null | |
$pathExclusions.Add($userPath + '\.jdks') > $null | |
$pathExclusions.Add('C:\Program Files\JetBrains') > $null | |
$pathExclusions.Add($userPath + '\.gradle') > $null | |
$pathExclusions.Add($userPath + '\.m2') > $null | |
$pathExclusions.Add('C:\ProgramData\chocolatey') > $null | |
$pathExclusions.Add($userPath + '\AppData\Local\Android\Sdk') > $null | |
$pathExclusions.Add('C:\Program Files\Microsoft SQL Server') > $null | |
$pathExclusions.Add('C:\Program Files (x86)\Microsoft SQL Server') > $null | |
# Process exclusions | |
$processExclusions.Add('devenv.exe') > $null | |
$processExclusions.Add('dotnet.exe') > $null | |
$processExclusions.Add('msbuild.exe') > $null | |
$processExclusions.Add('MSBuild.exe') > $null | |
$processExclusions.Add('node.exe') > $null | |
$processExclusions.Add('npm.cmd') > $null | |
$processExclusions.Add('node.js') > $null | |
$processExclusions.Add('perfwatson2.exe') > $null | |
$processExclusions.Add('ServiceHub.Host.Node.x86.exe') > $null | |
$processExclusions.Add('vbcscompiler.exe') > $null | |
$processExclusions.Add('VBCSCompiler.exe') > $null | |
$processExclusions.Add('vstest.console.exe') > $null | |
$processExclusions.Add('testhost.exe') > $null | |
$processExclusions.Add('datacollector.exe') > $null | |
$processExclusions.Add('CodeCoverage.exe') > $null | |
$processExclusions.Add('ServiceHub.Host.AnyCPU.exe') > $null | |
$processExclusions.Add('ServiceHub.IdentityHost.exe') > $null | |
$processExclusions.Add('ServiceHub.VSDetouredHost.exe') > $null | |
$processExclusions.Add('ServiceHub.SettingsHost.exe') > $null | |
$processExclusions.Add('ServiceHub.Host.dotnet.x64.exe') > $null | |
$processExclusions.Add('ServiceHub.ThreadedWaitDialog.exe') > $null | |
$processExclusions.Add('git.exe') > $null | |
$processExclusions.Add('github.exe') > $null | |
$processExclusions.Add('docker.exe') > $null | |
$processExclusions.Add('docker-compose.exe') > $null | |
$processExclusions.Add('python.exe') > $null | |
$processExclusions.Add('pythonw.exe') > $null | |
$processExclusions.Add('pip.exe') > $null | |
$processExclusions.Add('java.exe') > $null | |
$processExclusions.Add('javaw.exe') > $null | |
$processExclusions.Add('javac.exe') > $null | |
$processExclusions.Add('gradle.exe') > $null | |
$processExclusions.Add('mvn.cmd') > $null | |
$processExclusions.Add('idea64.exe') > $null | |
$processExclusions.Add('pycharm64.exe') > $null | |
$processExclusions.Add('webstorm64.exe') > $null | |
$processExclusions.Add('rider64.exe') > $null | |
$processExclusions.Add('code.exe') > $null | |
$processExclusions.Add('sqlservr.exe') > $null | |
$processExclusions.Add('mysqld.exe') > $null | |
$processExclusions.Add('postgres.exe') > $null | |
# Additional process exclusions | |
$processExclusions.Add('ServiceHub.Host.Node.x64.exe') > $null | |
$processExclusions.Add('ServiceHub.Host.CLR.x86.exe') > $null | |
$processExclusions.Add('ServiceHub.Host.CLR.x64.exe') > $null | |
$processExclusions.Add('ServiceHub.RoslynCodeAnalysisService.exe') > $null | |
$processExclusions.Add('iisexpress.exe') > $null | |
$processExclusions.Add('Microsoft.VisualStudio.Web.Host.exe') > $null | |
$processExclusions.Add('ServiceHub.DataWarehouseHost.exe') > $null | |
$processExclusions.Add('ScriptedSandbox64.exe') > $null | |
$processExclusions.Add('conhost.exe') > $null | |
$processExclusions.Add('IntelliTrace.exe') > $null | |
Write-Host "Alright! Let's set up those Windows Defender exclusions for your dev tools and folders." | |
Write-Host "" | |
# Set default projects folder and prompt user | |
$defaultProjectsFolder = Join-Path $userPath "source\repos" | |
$projectsFolder = Read-Host "Where's your projects folder? (Hit Enter to use default: $defaultProjectsFolder)" | |
if ([string]::IsNullOrWhiteSpace($projectsFolder)) { | |
$projectsFolder = $defaultProjectsFolder | |
} | |
if (Test-Path $projectsFolder) { | |
Write-Host "Adding Path Exclusion: " $projectsFolder | |
Add-MpPreference -ExclusionPath $projectsFolder | |
} else { | |
Write-Host "Heads up: That projects folder doesn't exist. We'll create it and add the exclusion." | |
New-Item -ItemType Directory -Force -Path $projectsFolder | |
Add-MpPreference -ExclusionPath $projectsFolder | |
} | |
foreach ($exclusion in $pathExclusions) | |
{ | |
if (Test-Path $exclusion) { | |
Write-Host "Adding Path Exclusion: " $exclusion | |
Add-MpPreference -ExclusionPath $exclusion | |
} else { | |
Write-Host "Path not found, skipping exclusion: " $exclusion | |
} | |
} | |
foreach ($exclusion in $processExclusions) | |
{ | |
Write-Host "Adding Process Exclusion: " $exclusion | |
Add-MpPreference -ExclusionProcess $exclusion | |
} | |
Write-Host "" | |
Write-Host "Here's what we've excluded for you:" | |
$prefs = Get-MpPreference | |
Write-Host "Excluded Paths:" | |
$prefs.ExclusionPath | Sort-Object | ForEach-Object { Write-Host " $_" } | |
Write-Host "Excluded Processes:" | |
$prefs.ExclusionProcess | Sort-Object | ForEach-Object { Write-Host " $_" } | |
Write-ColorOutput Yellow @" | |
IMPORTANT REMINDER: | |
You've just modified your Windows Defender settings. This might make your system a bit more vulnerable, | |
so be extra cautious with files from unknown sources. Remember, you're the captain of this ship now! | |
"@ | |
Write-Host "" | |
Write-Host "Happy coding! Enjoy those faster build times! 🚀💻" | |
Write-Host "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment