Introduction
PowerShell on Linux lets you use the same easy commands and scripts on Linux as on Windows. It helps you manage Linux systems with familiar tools.
Jump into concepts and practice - no test required
pwsh # Start PowerShell on Linux Get-Process # List running processes
pwsh Get-Process
pwsh Get-ChildItem /home/user
pwsh
ls -lpwsh
# This script shows the current date and lists files in home directory
Get-Date
Get-ChildItem $HOME
pwsh in the terminal.powershell.exe, start-ps, and shellps are not valid commands to start PowerShell on Linux.ls -l.Invoke-Linux ls -l, Run-Command 'ls -l', and Start-Linux ls -l are not valid syntax to run Linux commands.pwsh
$files = ls /etc | Where-Object { $_.Name -like '*.conf' }
$files.Countls /etc lists files in /etc. The Where-Object filters files whose names end with '.conf'.$files.Count returns the number of such files.pwsh $process = Get-Process -Name "bash" Write-Output $process.IdBut it returns an error: "Get-Process: The term 'Get-Process' is not recognized." What is the likely cause?
$env:USER to get the current user's name.Where-Object { $_.UserName -eq $env:USER } correctly compares the process owner to the current user.ps -u $USER | pwsh mixes Linux command with PowerShell incorrectly. Get-Process | Where-Object { $_.UserName -eq (whoami) } uses command output that may not match precisely. Get-Process | Where-Object { $_.UserName -eq $env:USERNAME } uses $env:USERNAME which is typically not set on Linux.