JekyllGHPages

Getting Started with PowerShell

Prerequisites

Before you begin, make sure you have the following:

Installation

Windows

PowerShell 7 is available via choco:

choco install powershell-core

macOS

brew install powershell/tap/powershell

Linux

# Ubuntu / Debian
sudo apt-get install -y powershell

Your First Script

Create a file called hello.ps1:

# hello.ps1 - Your first PowerShell script
param(
    [string]$Name = 'World'
)

$greeting = "Hello, $Name!"
Write-Output $greeting

# Bonus: Get some system info
$info = [ordered]@{
    User      = $env:USERNAME ?? $env:USER
    OS        = $PSVersionTable.OS
    PSVersion = $PSVersionTable.PSVersion
    Date      = Get-Date -Format 'yyyy-MM-dd'
}

[PSCustomObject]$info | Format-List

Tip: Use pwsh to launch PowerShell 7, not powershell (which launches Windows PowerShell 5.1).

Common Commands

Command Alias Description
Get-ChildItem ls, dir List files and folders
Set-Location cd, sl Change directory
Get-Content cat, type Read file contents
Select-Object select Pick specific properties
Where-Object where, ? Filter pipeline objects

Next Steps

Once you have PowerShell installed, check out the Markdown Feature Showcase to see what your static site generator can do.