Skip to content

Instantly share code, notes, and snippets.

@ian-p-cooke
Last active June 30, 2024 05:27
Show Gist options
  • Save ian-p-cooke/4e1713729b3676d2a5eaaf96b99978da to your computer and use it in GitHub Desktop.
Save ian-p-cooke/4e1713729b3676d2a5eaaf96b99978da to your computer and use it in GitHub Desktop.
powershell script to add WSL exclusions
$win_user = "ipc"
$linux_user = "ipc"
$package = "CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc"
$base_path = "C:\Users\" + $win_user + "\AppData\Local\Packages\" + $package + "\LocalState\rootfs"
$dirs = @("\bin", "\sbin", "\usr\bin", "\usr\sbin", "\home\" + $linux_user + "\.cargo\bin")
$dirs | ForEach { Add-MpPreference -ExclusionProcess ($base_path + $_ + "\*") }
Add-MpPreference -ExclusionPath $base_path
@rishispeets
Copy link

rishispeets commented Nov 19, 2018

Thanks for this, Ian! I was becoming really annoyed by the WSL speeds. I wrote about your workaround in a post. Let me know if you're cool with that and/or have any corrections. Cheers!

@thefallentree
Copy link

Please use this

$win_user = "ipc"
$linux_user = "ipc"
$package = "CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc"
$base_path = "C:\Users\" + $win_user + "\AppData\Local\Packages\" + $package + "\LocalState\rootfs"
$dirs = @("\bin", "\sbin", "\usr\bin", "\usr\sbin", ("\home\" + $linux_user + "\.cargo\bin"))
$dirs | ForEach { Add-MpPreference -ExclusionProcess ($base_path + $_ + "\*") }
Add-MpPreference -ExclusionPath $base_path

@nareddyt
Copy link

nareddyt commented Nov 30, 2018

Here is a version filled in with the directories on the default ubuntu $PATH. If all your tools are installed via apt, this should work for you.

$win_user = "tejun"
$linux_user = "nareddyt"
$package = "CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc"
$base_path = "C:\Users\" + $win_user + "\AppData\Local\Packages\" + $package + "\LocalState\rootfs"
$dirs = @("\usr\local\sbin", "\usr\local\bin", "\usr\sbin", "\usr\bin", "\sbin", "\bin", "\usr\games", "\usr\local\games")
$dirs | ForEach { Add-MpPreference -ExclusionProcess ($base_path + $_ + "\*") }
Add-MpPreference -ExclusionPath $base_path

@dayne
Copy link

dayne commented Dec 14, 2018

Thanks for this.

I end up using a bunch of custom paths for my tools. Wrote a ruby script to output a best guess as to the correct PowerShell script to fix up my environment:

https://gist.github.com/dayne/313981bc3ee6dbf8ee57eb3d58aa1dc0#file-1-wsl-defender-fix-md

@krschwab
Copy link

krschwab commented Dec 29, 2018

For anyone with Debian9, replace the $package line with:

$package = "TheDebianProject.DebianGNULinux_76v4gfsz19hv4"

@cbdj
Copy link

cbdj commented Jan 30, 2019

Does this resolve the IO performance issue (microsoft/WSL#873) on WSL ?

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