OpsaC - Operating as PowerShell code
published: March 14, 2024 author: Tinu tags: PowerShell - News categories: PowerShell-Cross-Platform
Sometimes, I would playing araound with Linux and test some Modules.
Using the Windows Subsystem for Linux on Windows to use Linux. To install WSL on your Windows, consult the Install Guide on Microsoft.
wsl --list --online
The following is a list of valid distributions that can be installed.
Install using 'wsl.exe --install <Distro>'.
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_7 Oracle Linux 8.7
OracleLinux_9_1 Oracle Linux 9.1
openSUSE-Leap-15.5 openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed openSUSE Tumbleweed
Install an Ubuntu on WSL.
wsl --install Ubuntu-22.04
Uninstall Ubuntu on WSL.
wsl --unregister Ubuntu-22.04
The best way to use Linux is PowerShell:
sudo apt-get clean all && sudo apt-get update
sudo apt-get install -y wget apt-transport-https software-properties-common
wget -q "https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb"
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get install -y powershell
sudo apt list powershell
Output:
Listing... Done
powershell/jammy,now 7.4.1-1.deb amd64 [installed]
N: There are 28 additional versions. Please use the '-a' switch to see them.
sudo apt-get install --only-upgrade powershell
To install AlmaLinux, open Microsoft Store, search for AlmaLinux 9 and install it. It’s not available as WSL-Distribution
sudo dnf clean all && sudo dnf update && sudo dnf --security update
curl https://packages.microsoft.com/config/rhel/9.0/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
sudo dnf install --assumeyes powershell
sudo dnf list powershell
Output:
Installed Packages
powershell.x86_64 7.4.1-1.rh @packages-microsoft-com-prod
sudo dnf update powershell
Start the Windows Terminal and open AlmaLinux-OS 9 or Ubuntu 22.04.3 LTS as a new tab.
List the local drives on Windows from the Linux:
ls /mnt
c d e f wsl wslg z
List the content of a specified path on Windows from the Linux:
ls /mnt/d/temp
Copy the profile.ps1 from Windows to Linux for all users. If you don’t have the profile.ps1 for cross-platform, here you find an example.
mkdir -p /home/tinux/.config/powershell
sudo cp -f -R /mnt/d/profile.ps1 /opt/microsoft/powershell/7/
Start PowerShell as user and then as root, that you can test the coloring of the profile.ps1.
Tip: In Windows Terminal press Alt and click the dropdown to select your Linux that you want to start. This split the current Terminal.
First, set the PowerShell Gallery as trusted then you can install the modules without to confirm that you trust the repository.
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -SourceLocation https://www.powershellgallery.com/api/v2
Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Trusted https://www.powershellgallery.com/api/v2
Start PowerShell as root to install modules for all users. I want to use two of the Modules from Jeff Hicks.
sudo pwsh
Install-Module -Scope AllUsers -Verbose -Name PSReadLine
# Jeff Hicks Modules
Install-Module -Scope AllUsers -Verbose -Name mySQLite
Install-Module -Scope AllUsers -Verbose -Name PSWorkItem
exit
Start PowerShell as user and initialize PSWorkItem and start the TUI Console.
pwsh
Initialize-PSWorkItemDatabase
Add-PSWorkItemCategory -Category Work -Description "business-related tasks" -PassThru -Force
Add-PSWorkItemCategory -Category Personal -Description "personal-related tasks" -PassThru -Force
Add-PSWorkItemCategory -Category Project -Description "project-related tasks" -PassThru -Force
Add-PSWorkItemCategory -Category Other -Description "something-related tasks" -PassThru -Force
Open-PSWorkItemConsole
or direct from bash
pwsh -Command "& {wic}"
Getting Started with PowerShell in Linux, AlamLinux Wiki, Jeff Hicks PSWorkItem