rumcajs
rumcajs

Reputation: 71

How to set Defender Exclusion in Powershell

I need to set folder exclusion for defender using powershell. The problem is that folder has dot in its name ../.m2/.. (folder for IDE IntelliJ IDEA). If I am trying to create this exclusion with this command:

Add-MpPreference -ExclusionPath "%HOMEPATH%/.m2"

defender takes it as file exclusion not as path, check this screenshot defender exclusions

I have tried different modifications of command which I have mentioned above but still same problem

Add-MpPreference -ExclusionPath "%HOMEPATH%\.m2"
Add-MpPreference -ExclusionPath "%HOMEPATH%\\.m2"
Add-MpPreference -ExclusionPath "%HOMEPATH%\.\.m2"
...

Could someone help me, how to do it?

Upvotes: 0

Views: 2517

Answers (2)

NotTheDr01ds
NotTheDr01ds

Reputation: 20823

The comment from @Theo appears to be the correct solution. In PowerShell, environment variables are accessed via $env:<variable_name> rather than %variable_name%.

Upvotes: 0

SijeDeHaan
SijeDeHaan

Reputation: 183

Use single quotes, not double quotes

Upvotes: -1

Related Questions