Home

Awesome

PowerShell WSL Interop

The Windows Subsystem for Linux (WSL) enables calling Linux commands directly within PowerShell via wsl.exe (e.g. wsl ls). While more convenient than a full context switch into WSL, it has the following limitations:

The Import-WslCommand function addresses these issues in the following ways:

The commands can receive both pipeline input as well as their corresponding arguments just as if they were native to Windows.

Additionally, they will honor any default parameters defined in a hash table called $WslDefaultParameterValues similar to $PSDefaultParameterValues. For example:

$WslDefaultParameterValues["grep"] = "-E"
$WslDefaultParameterValues["less"] = "-i"
$WslDefaultParameterValues["ls"] = "-AFh --group-directories-first"

If you use aliases or environment variables within your login profiles to set default parameters for commands, define a hash table called $WslDefaultParameterValues within your PowerShell profile and populate it as above for a similar experience.

Environment variables can also be set in a hash table called $WslEnvironmentVariables using the pattern $WslEnvironmentVariables["<NAME>"] = "<VALUE>".

The import of these functions replaces any PowerShell aliases that conflict with the commands.

Usage

Known Issues