GitXplorerGitXplorer
T

PSWsl

public
46 stars
2 forks
5 issues

Commits

List of commits on branch master.
Unverified
9f3a11dd03f084de5acc19e7542b096fce632f70

Added the WSL abbreviation expansion (#21)

iit-praktyk committed 6 years ago
Unverified
60eccc77a9b31d2e09429741488204399a56c405

Add Codacy badge (#20)

ccodacy-badger committed 6 years ago
Verified
e1994eba7afe7e09e0fcf23eccfa5ab1d156d8ad

add PowerShell core compatible badge

TTylerLeonhardt committed 6 years ago
Unverified
1ab8cb0f59e9180ccf0dfd2f1b6d9f4d3b63b20d

Fix a string split issue on powershell 5.1 (#19)

ppatrick330602 committed 6 years ago
Verified
7f72e5b99bb1af2cd2a4bdcd567335a1ef3f8df4

Release 0.2.2 (#16)

TTylerLeonhardt committed 7 years ago
Verified
9202bc0d213b1a8547dc19ed45bced755c461cdb

fixes single wsl distro issue (#15)

TTylerLeonhardt committed 7 years ago

README

The README file for this repository.

PSWsl

Codacy Badge Build status Core compatible

PSWsl is a PowerShell module for interacting with Windows Subsystem for Linux (WSL). If PowerShell Core exists on your WSL distibution, you can easily invoke commands that return deserialized objects:

In PowerShell Core on Windows

PS > $versionHashTable = Invoke-WslCommand -Distribution debian -Command '$PSVersionTable'
PS > $versionHashTable.Platform
Unix

Demo:

invoke-wslcommand

This module simply wraps the wsl.exe, wslconfig.exe, and all the distribution.exe's in a more PowerShell friendly/specific way.

Why?

  • Quickly test scripts and modules against linux without having to stand up a VM or container.
  • Write multi-OS scripts that leverage PowerShell on Windows while also interacting with a Linux environment.
  • Interact with Linux-only tools and utilities with PowerShell.

Installation

Note: To get PowerShell Core on your WSL distribution, follow the steps here.

PSWsl is available on the PowerShell Gallery:

Install-Module PSWsl

You can also grab the latest zip from GitHub and put that in your $env:PSModulePath under a PSWsl folder.

Usage

If you don't have PSWsl in your PSModulePath, you will need to import it manually with:

Import-Module path/to/your/PSWsl/PSWsl.psd1

From there you should be able to enter into PSSessions in WSL, invoke commands from your current session of PowerShell, get your distributions, and set the default distribution:

Enter into a PSSession in a WSL distribution

enter-wsldistribution

# use your default distribution
Enter-WslDistribution

# be specific
Enter-WslDistribution -DistributionName ubuntu

Invoke commands within a WSL distribution

invoke-wslcommand

# You can use a string command, script block, or file. You can also pipe in a distribution array
PS > $versionHashTable = Invoke-WslCommand -Distribution debian -ScriptBlock { $PSVersionTable }
PS > $versionHashTable.Platform
Unix

Get your distributions

# Get all
Get-WslDistribution

# Supports wildcards
Get-WslDistribution -DistributionName ubunt*

# Piping
Get-WslDistribution | Invoke-WslCommand -Command '$PSVersionTable'

Set the default distribution

# explicit
Set-DistributionDefault -DistributionName ubuntu

# Piping
Get-WslDistribution -DistributionName ubun* | Set-DistributionDefault

Running the tests

The Pester tests use mocks to mock specific executables so you shouldn't need any setup.

Just run Invoke-Pester from the test directory.