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):
Microsoft Store (Recommended)
- Open the Microsoft Store
- Search for "PowerShell"
- Select "PowerShell" by Microsoft
- Click "Get" or "Install"
Manual Installation
- Visit GitHub PowerShell Releases
- Download the MSI package for your system (x64 or x86)
- Run the installer and follow the prompts
Using Winget
powershellwinget install Microsoft.PowerShell
macOS
Using Homebrew (Recommended)
bashbrew install --cask powershellManual Installation
- Visit GitHub PowerShell Releases
- Download the package for macOS (.pkg file)
- Run the installer and follow the prompts
Linux
Ubuntu/Debian
# 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 powershellFedora/RHEL/CentOS
# 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 -yArch Linux
# Install from AUR
yay -S powershell-binLaunching 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.
Check if a profile exists:
powershellTest-Path $PROFILECreate a profile if it doesn't exist:
powershellNew-Item -Path $PROFILE -Type File -ForceEdit your profile:
powershellnotepad $PROFILE # Windows nano $PROFILE # macOS/Linux
Essential Profile Customizations
Add these to your profile for improved productivity:
# 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
# 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 -SkipPublisherCheckTerminal Integration
Windows Terminal Settings
For Windows Terminal, add these to your settings.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
- Clean up your profile: Keep it slim and efficient
- Use the right modules: Only load what you need
- Use PowerShell 7+: Much faster than older versions
- Consider script optimization: Use the Script Analyzerpowershell
Install-Module -Name PSScriptAnalyzer Invoke-ScriptAnalyzer -Path yourscript.ps1
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| Tab | Command completion |
| Ctrl+Space | Display parameter suggestions |
| F7 | Show command history |
| Ctrl+R | Search command history |
| Alt+F7 | Clear command history |
| Esc | Clear current line |
| Home/End | Move to start/end of line |
| Ctrl+Left/Right Arrow | Move one word left/right |
Common Tasks and Tips
Working with Objects
Unlike traditional shells, PowerShell works with objects, not text:
# Get processes and sort by memory usage
Get-Process | Sort-Object -Property WorkingSet64 -Descending | Select-Object -First 5Remote Management
# 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
# View current policy
Get-ExecutionPolicy
# Set a more permissive policy (for your user only)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserAdditional Resources
## Next Steps
Start by installing PowerShell, set up your profile with the configurations above, and gradually customize it to suit your workflow.