PowerShell Windows Subsystem for Linux
A wrapper for wsl.exe. It parses WSL output into standard PowerShell objects, provides safety checks for destructive operations, and automates the migration of distributions between drives.
π¨ Requirement: Windows 10/11 with WSL enabled.
Function Reference βΎοΈ PSGallery βΎοΈ Chocolatey βΎοΈ GitHub
Installing pwsl is available via the package repositories: PSGallery, Chocolatey and GitLab.
| βββββββββββ | βββββββββββ | βββββββββββ |
|---|---|---|
| π¦ PSGallery | |
|
| π¦ Chocolatey |
Additinonal Installation Options:
| βββββββββββ | βββββββββββ | βββββββββββ |
|---|---|---|
| πΌ Releases/Tags | |
|
Using nuget: See the packages page for installation instructions.
For instructions on adding
nuget sourcespackages from GitLab see Releases artifacts or via the Packages page.
The latest release artifacts can be downloaded from the Generic Assets Artifacts page.
# Clone the repository
git clone https://gitlab.com/phellams/pwsl.git
cd pwsl
import-module .\Standard wsl --list returns raw text (often with encoding issues). PWSL returns PowerShell objects.
$distros = Get-PwslList
$distros | Where-Object { $_.State -eq 'Running' }
Move-PwslDistro automates the manual Export -> Unregister -> Import workflow.
Logic Handled:
- Stops the running distro.
- Exports to a temporary location (with file size safety checks).
- Unregisters (deletes) the original only if the backup is valid.
- Imports to the new destination.
- Restores Default User: Injects
/etc/wsl.confso you don't log in asrootby default.
# Move Ubuntu to D: drive and set as default
Move-PwslDistro -Name "Ubuntu-24.04" -NewLocation "D:\WSL\Ubuntu" -SetAsDefault
When a distro is imported, WSL defaults the user to root. This script attempts to ask for your username and write it to /etc/wsl.conf automatically. If this fails, you will log in as root.
To fix manually inside the distro:
# Inside WSL
echo -e "[user]\ndefault=your_username" >> /etc/wsl.conf
The module registers a tab-completer. You can press [TAB] to cycle through installed distro names for commands like Stop-, Move-, or Enter-.
| Command | Description |
|---|---|
Get-PwslList |
Returns object list of installed distros (Name, State, Version). |
Get-PwslRunning |
Returns only running distros. |
Get-PwslAvailable |
Lists distros available for download (wsl --list --online). |
Enter-PwslDistro |
Enters the shell of a specific distro (wsl -d). |
| Command | Description |
|---|---|
Install-PwslDistro |
Installs a new distro from the online list. |
Stop-PwslDistro |
Terminates a running instance immediately. |
Register-PwslDistro |
Alias for Import. Registers a custom rootfs. |
Unregister-PwslDistro |
| Command | Description |
|---|---|
Move-PwslDistro |
Safely moves a distro to a new path. |
Export-PwslDistro |
Exports rootfs to a .tar file. |
Import-PwslDistro |
Imports a .tar file as a new distro. |
Install and Setup
# Check what is available
Get-PwslAvailable
# Install
Install-PwslDistro -Name "Debian"
# install in a specific location
# Note: Move-Pwsldistro will be called to perform move steps and will take addtional time
# Note: Default user must be the same as the one you specify during intereactive installation
Install-PwslDistro -Name "Debian" -InstallLocation "C:\WSL\Debian"Backup and res
# Create a snapshot
Export-PwslDistro -Name "Debian" -Path "C:\Backups\debian-snap.tar"
# Restore as a separate instance for testing
Import-PwslDistro -Name "Debian-Test" -InstallLocation "C:\WSL\Test" -SourceTar "C:\Backups\debian-snap.tar"Relocation
# Move to a different drive
Get-PwslList
# Default temp location is C:\Users\gsnow\AppData\Local\Temp
Move-PwslDistro -Name "Debian" -NewLocation "G:\WSL\Debian" -defaultUser "username"
# custom temp location
Move-PwslDistro -Name "Debian" -NewLocation "G:\WSL\Debian" -TempLocation "G:\Backups" -defaultUser "username"- The ability to enable and disble wsl via powershell
- The ability to list distro versions and perhaps install previous version if the need is there
- complete phwriter help metadata for accurate help output
Contributions are welcome! Please fork the repository and submit a Merge Request (MR) targeting the develop branch.
-
Fork the Project Click the "Fork" button in the top right corner of the repository page.
-
Clone your Fork
git clone [https://gitlab.com/YOUR_USERNAME/pwsl.git](https://gitlab.com/YOUR_USERNAME/pwsl.git) cd pwslmerge_requests/new) -
Create a Feature Branch Ensure you base your work on the develop branch:
git switch develop git switch -c feature/AmazingFeature
-
Commit your Changes
git commit -m 'feat: Add some AmazingFeature' -
Push to the Branch
git push origin feature/AmazingFeature
-
Open a Merge Request
- @wsl - Windows Subsystem for Linux (WSL) lets developers run a GNU/Linux environment inside a Windows environment.
- @shields.io - Shields.io provides a service to generate badges and other visual elements for your projects.
This module is released under the MIT License.