Run WSL commands from PowerShell — like cat
, grep
, ls
, and more.
-
Save the script as
Invoke-WslCommand.ps1
. -
Add it to your PowerShell profile so it loads automatically:
. "path-to/Invoke-WslCommand.ps1"
💡 You can check your PowerShell profile path with:
$PROFILE
To define wrapper functions for common Linux commands, add something like this to your PowerShell profile:
function global:cat {
Invoke-WslCommand -Command "cat" -Arguments $args
}
function global:grep {
Invoke-WslCommand -Command "grep" -Arguments $args
}
If you're replacing existing PowerShell aliases (like ls
), make sure to remove them first:
Remove-Item alias:ls -Force -ErrorAction SilentlyContinue
function global:ls {
Invoke-WslCommand -Command "ls" -Arguments $args
}
You can pipe your commands with ->
cat README.md -> grep "hello world"
- Run Linux tools directly from PowerShell
- Easily integrate WSL into your Windows workflow
- Customize and expand with your own command wrappers
Use this setup to unify your dev environment — best of both worlds: Windows + Linux!