Skip to content

Instantly share code, notes, and snippets.

@m4tlch
Forked from noelbundick/LICENSE
Created May 16, 2024 21:09
Show Gist options
  • Save m4tlch/f48eeed6aac8f22ece6d591569641530 to your computer and use it in GitHub Desktop.
Save m4tlch/f48eeed6aac8f22ece6d591569641530 to your computer and use it in GitHub Desktop.

Revisions

  1. @noelbundick noelbundick revised this gist Nov 1, 2018. 1 changed file with 17 additions and 4 deletions.
    21 changes: 17 additions & 4 deletions excludeWSL.ps1
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    ############

    # Find registered WSL environments
    $wslPaths = (Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | % { Get-ItemProperty $_.PSPath}).BasePath
    $wslPaths = (Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | ForEach-Object { Get-ItemProperty $_.PSPath}).BasePath

    # Get the current Windows Defender exclusion paths
    $currentExclusions = $(Get-MpPreference).ExclusionPath
    @@ -16,12 +16,25 @@ if (!$currentExclusions) {
    }

    # Find the WSL paths that are not excluded
    $exclusionsToAdd = ((diff $wslPaths $currentExclusions) | ? SideIndicator -eq "<=").InputObject
    $exclusionsToAdd = ((Compare-Object $wslPaths $currentExclusions) | Where-Object SideIndicator -eq "<=").InputObject

    # List of paths inside the Linux distro to exclude (https://github.com/Microsoft/WSL/issues/1932#issuecomment-407855346)
    $dirs = @("\bin", "\sbin", "\usr\bin", "\usr\sbin", "\usr\local\bin", "\usr\local\go\bin")

    # Add the missing entries to Windows Defender
    if ($exclusionsToAdd.Length -gt 0) {
    $exclusionsToAdd | % {
    $exclusionsToAdd | ForEach-Object {

    # Exclude paths from the root of the WSL install
    Add-MpPreference -ExclusionPath $_
    Write-Output "Added exclusion for $_"

    # Exclude processes contained inside WSL
    $rootfs = $_ + "\rootfs"
    $dirs | ForEach-Object {
    $exclusion = $rootfs + $_ + "\*"
    Add-MpPreference -ExclusionProcess $exclusion
    Write-Output "Added exclusion for $exclusion"
    }
    }
    }
    }
  2. @noelbundick noelbundick revised this gist Jun 14, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions excludeWSL.ps1
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,9 @@ $wslPaths = (Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss

    # Get the current Windows Defender exclusion paths
    $currentExclusions = $(Get-MpPreference).ExclusionPath
    if (!$currentExclusions) {
    $currentExclusions = ''
    }

    # Find the WSL paths that are not excluded
    $exclusionsToAdd = ((diff $wslPaths $currentExclusions) | ? SideIndicator -eq "<=").InputObject
  3. @noelbundick noelbundick revised this gist Jun 3, 2018. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions LICENSE
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    MIT License

    Copyright (c) 2018 Noel Bundick

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
  4. @noelbundick noelbundick created this gist May 27, 2018.
    24 changes: 24 additions & 0 deletions excludeWSL.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    ############
    # This script will add your WSL environments to the Windows Defender exclusion list so that
    # realtime protection does not have an adverse effect on performance.
    #
    # You should be aware that this could make your system less secure. Use at your own risk.
    # Note: This should be run from an administrative PowerShell prompt
    ############

    # Find registered WSL environments
    $wslPaths = (Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | % { Get-ItemProperty $_.PSPath}).BasePath

    # Get the current Windows Defender exclusion paths
    $currentExclusions = $(Get-MpPreference).ExclusionPath

    # Find the WSL paths that are not excluded
    $exclusionsToAdd = ((diff $wslPaths $currentExclusions) | ? SideIndicator -eq "<=").InputObject

    # Add the missing entries to Windows Defender
    if ($exclusionsToAdd.Length -gt 0) {
    $exclusionsToAdd | % {
    Add-MpPreference -ExclusionPath $_
    Write-Output "Added exclusion for $_"
    }
    }