Skip to content

PowerShell Installation and Configuration Guide

Introduction

PowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. Originally a Windows-only component, PowerShell is now open-source and available on Windows, macOS, and Linux.

Installation

Windows

PowerShell 5.1 comes pre-installed on Windows 10 and Windows Server 2016/2019. To install PowerShell 7 (the latest cross-platform version):

  1. Microsoft Store (Recommended)

    • Open the Microsoft Store
    • Search for "PowerShell"
    • Select "PowerShell" by Microsoft
    • Click "Get" or "Install"
  2. Manual Installation

  3. Using Winget

    powershell
    winget install Microsoft.PowerShell

macOS

  1. Using Homebrew (Recommended)

    bash
    brew install --cask powershell
  2. Manual Installation

Linux

Ubuntu/Debian

bash
# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

Fedora/RHEL/CentOS

bash
# Register the Microsoft signature key
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc

# Add the Microsoft repository
sudo dnf install https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm -y

# Install PowerShell
sudo dnf install powershell -y

Arch Linux

bash
# Install from AUR
yay -S powershell-bin

Launching PowerShell

  • Windows: Search for PowerShell in the Start menu
  • macOS/Linux: Open a terminal and type pwsh

Configuration for Efficient Use

Creating a PowerShell Profile

Your PowerShell profile is a script that runs when PowerShell starts. It's the perfect place for customizations.

  1. Check if a profile exists:

    powershell
    Test-Path $PROFILE
  2. Create a profile if it doesn't exist:

    powershell
    New-Item -Path $PROFILE -Type File -Force
  3. Edit your profile:

    powershell
    notepad $PROFILE  # Windows
    nano $PROFILE     # macOS/Linux

Essential Profile Customizations

Add these to your profile for improved productivity:

powershell
# Import modules
Import-Module posh-git
Import-Module PSReadLine

# Custom prompt (example with git status)
function prompt {
    $location = Get-Location
    $gitBranch = git branch --show-current 2>$null
    $gitStatus = ""
    if ($gitBranch) {
        $gitStatus = " [$gitBranch]"
    }
    "PS $location$gitStatus> "
}

# Useful aliases
Set-Alias -Name g -Value git
Set-Alias -Name ll -Value Get-ChildItem
Set-Alias -Name touch -Value New-Item

# PSReadLine configuration
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -Colors @{
    Command            = 'Yellow'
    Parameter          = 'DarkCyan'
    InlinePrediction   = 'DarkGray'
}

Installing Essential Modules

powershell
# PowerShellGet for managing modules
Install-Module -Name PowerShellGet -Force

# Git integration
Install-Module posh-git -Scope CurrentUser -Force

# Modern Directory listing
Install-Module -Name Terminal-Icons -Scope CurrentUser -Force

# Better history management
Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

Terminal Integration

Windows Terminal Settings

For Windows Terminal, add these to your settings.json:

json
{
    "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
    "hidden": false,
    "name": "PowerShell 7",
    "source": "Windows.Terminal.PowershellCore",
    "colorScheme": "One Half Dark",
    "fontFace": "CascadiaCode NF",
    "useAcrylic": true,
    "acrylicOpacity": 0.8
}

macOS/Linux Terminal

Use a modern terminal like iTerm2 (macOS) or Terminator (Linux) with a Nerd Font for best results.

Performance Tips

  1. Clean up your profile: Keep it slim and efficient
  2. Use the right modules: Only load what you need
  3. Use PowerShell 7+: Much faster than older versions
  4. Consider script optimization: Use the Script Analyzer
    powershell
    Install-Module -Name PSScriptAnalyzer
    Invoke-ScriptAnalyzer -Path yourscript.ps1

Keyboard Shortcuts

ShortcutAction
TabCommand completion
Ctrl+SpaceDisplay parameter suggestions
F7Show command history
Ctrl+RSearch command history
Alt+F7Clear command history
EscClear current line
Home/EndMove to start/end of line
Ctrl+Left/Right ArrowMove one word left/right

Common Tasks and Tips

Working with Objects

Unlike traditional shells, PowerShell works with objects, not text:

powershell
# Get processes and sort by memory usage
Get-Process | Sort-Object -Property WorkingSet64 -Descending | Select-Object -First 5

Remote Management

powershell
# Start a remote session
Enter-PSSession -ComputerName server01 -Credential (Get-Credential)

# Run a command remotely
Invoke-Command -ComputerName server01,server02 -ScriptBlock { Get-Service -Name "BITS" }

Script Execution Policy

powershell
# View current policy
Get-ExecutionPolicy

# Set a more permissive policy (for your user only)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Additional Resources


## Next Steps

Start by installing PowerShell, set up your profile with the configurations above, and gradually customize it to suit your workflow.