To exclude some folder from the defender list can be used cmdlet Set-MpPreference
Manly, now you can stop reading, go to the PowerShell and update excludes:)
But if you are want to see how to perform this in more detail — welcome under the habrcut.
UPD: Added a script to add selected folder to excluded Defender locations (at the end of the post)
For the beginning, let's go through the current excluded folders list.
To perform this operation we need to open the PowerShell session with admin rights and execute next commands
![image](https://habrastorage.org/r/w1560/webt/um/vy/tb/umvytbdfpjsbymd6hvxf2n-jqwq.png)
As you see Rider and Pycharm already added some folders on my machine
Let's remove the specified repositories folders and make the rule more generic:
![image](https://habrastorage.org/r/w1560/webt/pa/ac/o1/paaco1v-ayi5uij2kkg08yjx-is.png)
Line by line:
Store our folders list to a new variable
Asserting the list is copied.
Removes «C:\Users\sync\Pycharm» «C:\Users\sync\Rider» and «D:\Sources\B*» folders from the list. You probably will have some another pattern.
Verifying the resulting list.
As a more generic folders filtering could be used something like this
but double check before moving to the next step.
Adding new folders to the excluded list:
As we are removing the paths added by rider and Pycharm the environment can start working slower. So it's the time to add the folders with our sources.
![image](https://habrastorage.org/r/w1560/webt/bw/77/im/bw77imdzcebimb4xl7p7k0yrkge.png)
The first 2 lines intended to add Rider and Pycharm projects.
Then adding our additional source folders path.
And in the latest command just verifying the resulting list.
And now time to save new folders to defender exclude list:
![image](https://habrastorage.org/r/w1560/webt/pf/uv/os/pfuvosk18pg7iitezxvnmadsdoi.png)
The first command just to double-check the folders collection.
Store our changed exclude list to Defender:
And verifying the result:
Perfest! Defender will never cause again the IDE freezes
Now you can save this code under the project folder and ship with your sources.
Manly, now you can stop reading, go to the PowerShell and update excludes:)
But if you are want to see how to perform this in more detail — welcome under the habrcut.
UPD: Added a script to add selected folder to excluded Defender locations (at the end of the post)
For the beginning, let's go through the current excluded folders list.
To perform this operation we need to open the PowerShell session with admin rights and execute next commands
$defenderSettings = Get-MpPreference
$defenderSettings.ExclusionPath
![image](https://habrastorage.org/webt/um/vy/tb/umvytbdfpjsbymd6hvxf2n-jqwq.png)
As you see Rider and Pycharm already added some folders on my machine
Let's remove the specified repositories folders and make the rule more generic:
![image](https://habrastorage.org/webt/pa/ac/o1/paaco1v-ayi5uij2kkg08yjx-is.png)
Line by line:
$currentItems=@($defenderSettings.ExclusionPath)
Store our folders list to a new variable
$currentItems
Asserting the list is copied.
$newItems = $currentItems -notlike "C:\Users\sync\Pycharm"
$newItems = $newItems -notlike "C:\Users\sync\Rider"
$newItems = $newItems -notlike "D:\Sources\B*"
Removes «C:\Users\sync\Pycharm» «C:\Users\sync\Rider» and «D:\Sources\B*» folders from the list. You probably will have some another pattern.
$newItems
Verifying the resulting list.
As a more generic folders filtering could be used something like this
$newItems = $currentItems -notlike "C:\Users*\Pycharm"
but double check before moving to the next step.
Adding new folders to the excluded list:
As we are removing the paths added by rider and Pycharm the environment can start working slower. So it's the time to add the folders with our sources.
![image](https://habrastorage.org/webt/bw/77/im/bw77imdzcebimb4xl7p7k0yrkge.png)
$updatedList=$newItems
$updatedList += "C:\Users\sync\PycharmProjects\"
$updatedList += "C:\Users\sync\RiderProjects\"
$updatedList += "D:\Sources\"
$updatedList += "C:\Users\sync\source\repos"
$updatedList
The first 2 lines intended to add Rider and Pycharm projects.
Then adding our additional source folders path.
And in the latest command just verifying the resulting list.
And now time to save new folders to defender exclude list:
![image](https://habrastorage.org/webt/pf/uv/os/pfuvosk18pg7iitezxvnmadsdoi.png)
The first command just to double-check the folders collection.
Store our changed exclude list to Defender:
Set-MpPreference -ExclusionPath $updatedList
And verifying the result:
Get-MpPreference | %{$_.ExclusionPath}
Perfest! Defender will never cause again the IDE freezes
Bonus! Script to add current folder to excludes list:
$defenderSettings = Get-MpPreference
$currentItems=@($defenderSettings.ExclusionPath)
$currentItems +=$pwd.Path
$currentItems
Set-MpPreference -ExclusionPath $currentItems
Now you can save this code under the project folder and ship with your sources.
Demonstation of work
![](https://habrastorage.org/r/w1560/webt/pv/a6/_c/pva6_cjw91rblhotqbzvfzxzvl4.png)
![](https://habrastorage.org/webt/pv/a6/_c/pva6_cjw91rblhotqbzvfzxzvl4.png)