PowerShell 7 is Microsoft’s cross-platform automation framework that runs natively on Linux, macOS, and Windows. Built on .NET, it brings a full-featured shell and scripting language to Linux systems – making it a solid choice for administrators managing hybrid environments across Azure, AWS, and on-premises infrastructure. This guide walks through installing PowerShell 7 on Ubuntu 24.04/22.04 and Debian 13/12 from the official Microsoft APT repository, then covers practical usage for Linux system administration.

Why PowerShell 7 on Linux?

If you manage infrastructure across multiple platforms, PowerShell 7 gives you a consistent scripting environment everywhere. Here is what makes it worth installing on your Linux boxes:

  • Cross-platform automation – Write scripts once, run them on Linux, Windows, and macOS without modification
  • Azure and AWS management – Native modules for managing cloud resources directly from the terminal
  • Object-oriented pipeline – Unlike traditional shells that pipe text, PowerShell pipes structured objects between commands
  • Built-in remoting – SSH-based remoting to manage remote Linux and Windows machines from a single session
  • Rich module ecosystem – Thousands of modules available through the PowerShell Gallery for every task imaginable
  • DSC (Desired State Configuration) – Configuration management built right into the platform

Prerequisites

Before starting the installation, make sure you have the following in place:

  • A running Ubuntu 24.04/22.04 or Debian 13/12 system
  • A user account with sudo privileges
  • A working internet connection
  • The apt-transport-https, curl, and gpg packages installed

Update your system packages before proceeding:

sudo apt update && sudo apt upgrade -y

Install the required dependencies:

sudo apt install -y curl gpg apt-transport-https software-properties-common

Step 1 – Add the Microsoft APT Repository

Microsoft maintains an official APT repository for PowerShell and other .NET packages. Start by downloading and installing the Microsoft GPG key:

curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-archive-keyring.gpg

Now add the Microsoft APT repository. Choose the command that matches your distribution.

For Ubuntu 24.04 (Noble):

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/ubuntu/24.04/prod noble main" | sudo tee /etc/apt/sources.list.d/microsoft.list

For Ubuntu 22.04 (Jammy):

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/ubuntu/22.04/prod jammy main" | sudo tee /etc/apt/sources.list.d/microsoft.list

For Debian 13 (Trixie):

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/13/prod trixie main" | sudo tee /etc/apt/sources.list.d/microsoft.list

For Debian 12 (Bookworm):

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft-archive-keyring.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" | sudo tee /etc/apt/sources.list.d/microsoft.list

Verify the repository file was created:

cat /etc/apt/sources.list.d/microsoft.list

You should see the repository line you just added. If the file is empty or missing, repeat the steps above.

Step 2 – Install PowerShell 7

Update the package index to pull metadata from the newly added repository, then install PowerShell:

sudo apt update
sudo apt install -y powershell

The installation pulls in the .NET runtime and all required dependencies automatically. Depending on your connection speed, this may take a minute or two.

Step 3 – Verify the Installation

Confirm PowerShell 7 is installed and working by checking the version:

pwsh --version

Expected output:

PowerShell 7.4.x

Check the binary location to confirm it installed to the expected path:

which pwsh

This should return /usr/bin/pwsh. You can now launch an interactive PowerShell session:

pwsh

Your prompt changes to PS /home/username>, indicating you are inside a PowerShell session. To exit back to your regular shell, type exit.

Step 4 – Basic PowerShell Usage on Linux

If you are coming from Bash, PowerShell works differently in some fundamental ways. Here are the essentials to get productive quickly.

Process Management

List running processes with Get-Process, which is the PowerShell equivalent of ps aux:

Get-Process

Filter for a specific process:

Get-Process -Name "nginx"

Sort processes by CPU usage and show the top 10:

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10

Service Management

On Linux, PowerShell interacts with systemd through its service cmdlets. Note that Get-Service is not natively available on Linux, but you can query systemd directly:

# List all active services via systemctl
& systemctl list-units --type=service --state=running

# Check status of a specific service
& systemctl status nginx

# Restart a service
& sudo systemctl restart nginx

The Object Pipeline

The biggest difference from Bash is that PowerShell pipes structured objects, not plain text. This means you can access properties directly without parsing text with awk or grep:

# Get all processes using more than 100MB of memory
Get-Process | Where-Object { $_.WorkingSet64 -gt 100MB } | Select-Object Name, @{Name='MemoryMB';Expression={[math]::Round($_.WorkingSet64/1MB,2)}}

# Get files larger than 50MB in a directory
Get-ChildItem /var/log -Recurse | Where-Object { $_.Length -gt 50MB } | Select-Object FullName, @{Name='SizeMB';Expression={[math]::Round($_.Length/1MB,2)}}

Working with Files and Directories

PowerShell provides cmdlets that map to familiar Linux commands, plus additional functionality:

# List files (equivalent to ls -la)
Get-ChildItem -Force

# Read file contents (equivalent to cat)
Get-Content /etc/hostname

# Search for text in files (equivalent to grep)
Select-String -Path "/var/log/syslog" -Pattern "error" -CaseSensitive:$false

# Create a directory
New-Item -ItemType Directory -Path "/tmp/powershell-test"

# Copy files
Copy-Item -Path "/etc/hosts" -Destination "/tmp/hosts.backup"

Installing PowerShell Modules

PowerShell modules extend functionality significantly. Install them from the PowerShell Gallery:

# Search for a module
Find-Module -Name "PSScriptAnalyzer"

# Install a module for the current user
Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -Force

# List installed modules
Get-InstalledModule

Step 5 – Install the Az Module for Azure Management

If you manage Azure resources, the Az PowerShell module lets you handle everything from VMs to storage accounts directly from your Linux terminal. Launch a PowerShell session and install the module:

pwsh -Command "Install-Module -Name Az -Repository PSGallery -Scope CurrentUser -Force"

The Az module is large, so the installation takes a few minutes. Once installed, verify it:

pwsh -Command "Get-InstalledModule -Name Az | Select-Object Name, Version"

Connect to your Azure account and start managing resources:

# Start PowerShell
pwsh

# Connect to Azure (opens browser for authentication)
Connect-AzAccount

# List resource groups
Get-AzResourceGroup | Format-Table ResourceGroupName, Location

# List virtual machines
Get-AzVM | Format-Table Name, ResourceGroupName, Location

# Get the status of all VMs
Get-AzVM -Status | Select-Object Name, ResourceGroupName, PowerState

Step 6 – Install AWS.Tools for AWS Management

For AWS environments, the modular AWS.Tools packages let you install only the service modules you need, keeping things lightweight:

pwsh -Command "Install-Module -Name AWS.Tools.Installer -Scope CurrentUser -Force"

Then install the specific service modules you work with:

pwsh -Command "Install-AWSToolsModule AWS.Tools.EC2, AWS.Tools.S3, AWS.Tools.IAM -Scope CurrentUser -Force"

Verify the installation and configure your credentials:

# Start PowerShell
pwsh

# Verify installed AWS modules
Get-InstalledModule -Name "AWS.Tools.*" | Select-Object Name, Version

# Set your AWS credentials
Set-AWSCredential -AccessKey "YOUR_ACCESS_KEY" -SecretKey "YOUR_SECRET_KEY" -StoreAs default

# List EC2 instances
Get-EC2Instance -Region us-east-1 | ForEach-Object { $_.Instances } | Select-Object InstanceId, InstanceType, State

# List S3 buckets
Get-S3Bucket | Format-Table BucketName, CreationDate

Step 7 – PowerShell SSH Remoting

PowerShell 7 supports SSH-based remoting, which is the preferred method on Linux. This lets you run PowerShell commands on remote machines over SSH without WinRM.

Configure SSH for PowerShell Remoting

On the remote machine, add a PowerShell subsystem to the SSH configuration:

sudo tee -a /etc/ssh/sshd_config <<'EOF'

# PowerShell SSH Remoting Subsystem
Subsystem powershell /usr/bin/pwsh -sshs -NoLogo -NoProfile
EOF

Restart the SSH service to apply the change:

sudo systemctl restart sshd

Verify sshd restarted without errors:

sudo systemctl status sshd

Connect to a Remote Machine

From your local PowerShell session, create a remote session over SSH:

# Start an interactive remote session
Enter-PSSession -HostName 192.168.1.100 -UserName admin -SSHTransport

# Or run a single command on the remote machine
Invoke-Command -HostName 192.168.1.100 -UserName admin -SSHTransport -ScriptBlock {
    Get-Process | Sort-Object CPU -Descending | Select-Object -First 5
}

# Run commands on multiple remote machines
Invoke-Command -HostName "server1","server2","server3" -UserName admin -SSHTransport -ScriptBlock {
    hostname
    Get-Process | Measure-Object | Select-Object -ExpandProperty Count
}

Step 8 – Create and Run PowerShell Scripts on Linux

PowerShell scripts use the .ps1 extension and work the same way on Linux as they do on Windows.

Create a Simple Script

Create a script that gathers basic system information:

cat > ~/scripts/system-report.ps1 <<'SCRIPT'
#!/usr/bin/env pwsh

# System Report Script
$report = [PSCustomObject]@{
    Hostname    = (hostname)
    DateTime    = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    Uptime      = (& uptime -p)
    KernelVer   = (& uname -r)
    CPUCount    = (& nproc)
    TotalMemGB  = [math]::Round((Get-Content /proc/meminfo | Select-String "MemTotal" | ForEach-Object { ($_ -split '\s+')[1] }) / 1MB, 2)
    DiskUsage   = (& df -h / | Select-Object -Last 1)
}

$report | Format-List

# Top 5 memory-consuming processes
Write-Output "`n--- Top 5 Processes by Memory ---"
Get-Process | Sort-Object WorkingSet64 -Descending | Select-Object -First 5 Name, @{N='MemMB';E={[math]::Round($_.WorkingSet64/1MB,2)}} | Format-Table -AutoSize
SCRIPT

Make it executable and run it:

mkdir -p ~/scripts
chmod +x ~/scripts/system-report.ps1
pwsh ~/scripts/system-report.ps1

Schedule Scripts with Cron

Run PowerShell scripts on a schedule using standard cron:

# Run the system report every day at 8 AM
(crontab -l 2>/dev/null; echo "0 8 * * * /usr/bin/pwsh /home/$USER/scripts/system-report.ps1 >> /var/log/system-report.log 2>&1") | crontab -

Verify the cron entry was added:

crontab -l

Step 9 – Configure PSReadLine for a Better Terminal Experience

PSReadLine is bundled with PowerShell 7 and provides command-line editing features similar to what you get with Bash readline. Customize it by creating a PowerShell profile:

pwsh -Command "New-Item -Path \$PROFILE -ItemType File -Force"

Add your PSReadLine configuration to the profile:

cat > ~/.config/powershell/Microsoft.PowerShell_profile.ps1 <<'PROFILE'
# PSReadLine Configuration
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

# Useful aliases
Set-Alias -Name ll -Value Get-ChildItem
Set-Alias -Name grep -Value Select-String

# Custom prompt
function prompt {
    $currentDir = (Get-Location).Path.Replace($HOME, "~")
    "PS $currentDir> "
}
PROFILE

Verify the profile loads correctly:

pwsh -NoExit -Command "Write-Output 'Profile loaded successfully'"

Key features you now have:

  • Predictive IntelliSense – Shows suggestions based on your command history as you type
  • ListView predictions – Displays suggestions in a dropdown list
  • Emacs keybindings – Ctrl+A, Ctrl+E, Ctrl+K, and other familiar shortcuts work as expected
  • History search – Up/Down arrows search through history matching what you have already typed
  • Tab completion – Menu-style tab completion for commands, parameters, and file paths

Step 10 – VS Code Integration

Visual Studio Code with the PowerShell extension provides the best editing and debugging experience for PowerShell scripts on Linux.

Install VS Code if you have not already:

sudo apt install -y code

If VS Code is not available from your default repositories, install it from the Microsoft repository (which you already added in Step 1):

sudo apt update && sudo apt install -y code

Install the PowerShell extension from the command line:

code --install-extension ms-vscode.powershell

Verify the extension is installed:

code --list-extensions | grep -i powershell

The PowerShell extension provides:

  • Syntax highlighting and IntelliSense for .ps1 files
  • Integrated PowerShell terminal
  • Script debugging with breakpoints
  • Code formatting with PSScriptAnalyzer rules
  • Function and variable navigation

To configure VS Code to use PowerShell 7 as the default integrated terminal, add this to your settings.json:

{
    "terminal.integrated.defaultProfile.linux": "pwsh",
    "terminal.integrated.profiles.linux": {
        "pwsh": {
            "path": "/usr/bin/pwsh",
            "icon": "terminal-powershell"
        }
    },
    "powershell.powerShellDefaultVersion": "PowerShell (pwsh)"
}

Troubleshooting

Package not found after adding the repository

If apt install powershell fails with “Unable to locate package,” the repository may not have been added correctly. Check the repository file:

cat /etc/apt/sources.list.d/microsoft.list

Make sure the codename matches your distribution. Also verify the GPG key is present:

ls -la /usr/share/keyrings/microsoft-archive-keyring.gpg

If the file is missing or has zero size, re-download it:

curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-archive-keyring.gpg

pwsh crashes or fails to start

If PowerShell crashes on launch, it may be a .NET dependency issue. Check the installed dependencies:

apt list --installed 2>/dev/null | grep -E "libicu|libssl|dotnet"

Install any missing ICU or SSL libraries:

sudo apt install -y libicu-dev libssl-dev

If the issue persists, try running PowerShell with trace output to identify the problem:

DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 pwsh

Module installation fails with permission errors

Always install modules with -Scope CurrentUser to avoid permission issues. If you previously installed a module system-wide and need to fix it:

pwsh -Command "Install-Module -Name ModuleName -Scope CurrentUser -Force -AllowClobber"

SSH remoting fails to connect

Verify that the PowerShell subsystem is configured on the remote host:

grep -i "subsystem powershell" /etc/ssh/sshd_config

Make sure pwsh is installed on the remote machine and the path in the subsystem line is correct:

which pwsh

After making any changes to sshd_config, restart the SSH service:

sudo systemctl restart sshd && sudo systemctl status sshd

PowerShell profile not loading

Check the profile path and verify the file exists:

pwsh -Command "Write-Output \$PROFILE; Test-Path \$PROFILE"

The profile directory should be ~/.config/powershell/. If the directory does not exist, create it:

mkdir -p ~/.config/powershell

Updating PowerShell

Since PowerShell is installed through APT, updates come through the standard package manager:

sudo apt update && sudo apt upgrade powershell -y

Verify the new version after upgrading:

pwsh --version

Wrapping Up

PowerShell 7 on Ubuntu and Debian gives you a capable cross-platform automation tool that fits right into existing Linux workflows. With the Microsoft APT repository configured, you get regular updates through the standard package manager. Combined with the Az and AWS.Tools modules, SSH remoting, and VS Code integration, it provides a solid foundation for managing hybrid infrastructure from a single scripting environment. The object-oriented pipeline alone makes it worth learning if you spend time parsing text output from traditional Linux commands.

LEAVE A REPLY

Please enter your comment!
Please enter your name here