PowerShell: Enabling WSL on Linux

Steps

PowerShell 6.0 gives the PowerShell users the opportunity to use their PowerShell knowledge across Windows, Linux and Mac operating systems.

We can install PowerShell 6.00 RC in a Windows 10 box.

How about Linux and Mac versions?

We can enable Windows Subsystem for Linux (WSL) to explore PowerShell on a Linux box. WSL initially came with an Ubuntu version of Linux. Now there are more. Below shown execution is on a  SUSE Linux Enterprise Server on Windows 10. Next step is to install SUSE Linux Enterprise Server 12(SLES) on a Windows box.

Another option is to install an Ubuntu 16.04 VM and install PowerShell on it, being a Window 10 user it's expensive to create a VM and give the host machine resources for that. However, Operating system before Window 10 must go for VM option.

 

1. Enable Windows Subsystem for Linux.

Open an elevated PowerShell console and execute code.

1.Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

2. Installing SUSE Linux shell.

 

This link will redirect you to the Window Store.    

 

3.  Installing PowerShell 6.0.0 RC in SLES in windows.

Open the installed SLES shell and follow steps (below steps are taken from PowerShell repo in GitHub.)

 
# Register the Microsoft signature key
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
 
# Add the Microsoft Product feed
curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/zypp/repos.d/microsoft.repo
 
# Update the list of products
sudo zypper update
 
# Install PowerShell
sudo zypper install powershell 

 

All of the above tasks took will not take more than 15 minutes.  

The amazing stuff is about the $Profile. We can reuse $Profile in PowerShell 5.1 to PowerShell 6.0.0 RC in windows and SLES without any code change if the code inside the $Profile script is supported across all platforms with.

A one-liner can do this.

1.Copy-Item /mnt/c/Users/user1/Document/WindowsPowerShell/Microsoft.PowerShell_profile.ps $Profile -Force