Skip to content

Instantly share code, notes, and snippets.

@darvell
Created October 23, 2017 00:20
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save darvell/edbc758b11ea4dcd7226b7c9f1821196 to your computer and use it in GitHub Desktop.
Save darvell/edbc758b11ea4dcd7226b7c9f1821196 to your computer and use it in GitHub Desktop.
Adds useful exceptions to Windows Defender for node.js developers.
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
Break
}
Write-Host "Excluding appdata NPM folder and Node.JS install folder from Windows Defender."
Add-MpPreference -ExclusionPath ([System.Environment]::ExpandEnvironmentVariables("%APPDATA%\npm\"))
Add-MpPreference -ExclusionPath (Get-ItemProperty "HKLM:SOFTWARE\Node.js" | Select-Object -Property InstallPath)
Write-Host "Excluding node related executables from Windows Defender."
# TODO: Clean up. Do I need .exe? Do I need full path? Can't find a real answer. Brute forcing works though the security risk is real.
# Maybe don't run this in an enterprise environment. Fork if you have a good answer :)
("node", "node.exe", "Expo XDE.exe", "yarn", "yarn.exe") | foreach {Add-MpPreference -ExclusionProcess $_}
@timrobinson33
Copy link

A corresponding "undo" script would be really useful. do we just replace "Add-MpPreference" with "Remove-MpPreference" ?

@matiniamirhossein
Copy link

I really couldn't do anything with npm until I ran this. Thanks.

@gethari
Copy link

gethari commented Mar 22, 2023

Wow, thank you

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