pwsh

PowerShell syntax reference — cmdlets, objects, pipelines, filtering, comparison operators, and Bash-to-PowerShell command equivalents

15 stars

Best use case

pwsh is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

PowerShell syntax reference — cmdlets, objects, pipelines, filtering, comparison operators, and Bash-to-PowerShell command equivalents

Teams using pwsh should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/pwsh/SKILL.md --create-dirs "https://raw.githubusercontent.com/ifiokjr/oh-pi/main/packages/skills/skills/pwsh/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/pwsh/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How pwsh Compares

Feature / AgentpwshStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

PowerShell syntax reference — cmdlets, objects, pipelines, filtering, comparison operators, and Bash-to-PowerShell command equivalents

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# PowerShell Skill

Use this skill whenever the user's shell is PowerShell (pwsh). All commands must use PowerShell syntax — cmdlets, not Bash/POSIX syntax. PowerShell deals in **objects**, not plain text.

## Core Concepts

PowerShell passes objects through pipelines, not text. Every cmdlet outputs structured objects with properties and methods. This is the single biggest difference from Bash.

## Variables

```powershell
# All variables start with $
$name = "World"
$count = 42
$files = Get-ChildItem

# Environment variables — $env: prefix
$env:PATH
$env:HOME
$env:USERPROFILE

# Automatic variables
$_                        # Current pipeline object
$?                        # Success status of last command
$LASTEXITCODE             # Exit code of last external program
$args                     # Script arguments
$PSVersionTable           # PowerShell version info
```

## Command Equivalents

| Task                   | Bash                   | PowerShell                                              |
| ---------------------- | ---------------------- | ------------------------------------------------------- |
| List files             | `ls -la`               | `Get-ChildItem` or `ls` (alias)                         |
| Find files recursively | `find . -name '*.rs'`  | `Get-ChildItem -Recurse -Filter "*.rs"` or `ls -r *.rs` |
| Current directory      | `pwd`                  | `Get-Location` or `pwd` (alias)                         |
| Change directory       | `cd /path`             | `Set-Location /path` or `cd /path` (alias)              |
| Read file              | `cat file.txt`         | `Get-Content file.txt` or `cat file.txt`                |
| Write file             | `echo "text" > f.txt`  | `"text" \| Out-File f.txt` or `"text" > f.txt`          |
| Append to file         | `echo "text" >> f.txt` | `"text" \| Out-File -Append f.txt` or `"text" >> f.txt` |
| Create directory       | `mkdir -p path`        | `New-Item -ItemType Directory path` or `mkdir path`     |
| Create file            | `touch file.txt`       | `New-Item -ItemType File file.txt`                      |
| Copy                   | `cp src dst`           | `Copy-Item src dst` or `cp src dst`                     |
| Move                   | `mv src dst`           | `Move-Item src dst` or `mv src dst`                     |
| Remove                 | `rm file`              | `Remove-Item file` or `rm file`                         |
| Recursive remove       | `rm -rf dir`           | `Remove-Item -Recurse -Force dir` or `rm -r -fo dir`    |
| Filter text            | `grep pattern`         | `Select-String -Pattern "pattern"` or `sls "pattern"`   |
| Replace text           | `sed 's/a/b/g'`        | `-replace 'a', 'b'` operator                            |
| Count lines            | `wc -l`                | `Measure-Object -Line`                                  |
| Sort                   | `sort`                 | `Sort-Object` or `sort`                                 |
| Head                   | `head -5`              | `Select-Object -First 5`                                |
| Tail                   | `tail -5`              | `Select-Object -Last 5`                                 |
| Tail follow            | `tail -f log`          | `Get-Content -Tail 10 -Wait log`                        |
| Process list           | `ps aux`               | `Get-Process` or `ps`                                   |
| Kill process           | `kill PID`             | `Stop-Process -Id PID` or `kill -Id PID`                |
| Get help               | `man cmd`              | `Get-Help cmd -Full` or `help cmd`                      |
| Find command           | `man -k keyword`       | `Get-Command *keyword*`                                 |
| Date                   | `date`                 | `Get-Date` or `date`                                    |
| Sleep                  | `sleep 1`              | `Start-Sleep -Seconds 1` or `sleep 1`                   |
| Download file          | `wget url`             | `Invoke-WebRequest url -OutFile file`                   |
| Environment vars       | `env`                  | `Get-ChildItem env:` or `ls env:`                       |
| Which/type             | `which cmd`            | `Get-Command cmd` or `gcm cmd`                          |
| Exit code              | `$?`                   | `$LASTEXITCODE` (external) or `$?` (cmdlet)             |
| Source file            | `. file.sh`            | `. .\file.ps1`                                          |
| Background job         | `cmd &`                | `Start-Job { cmd }` or `cmd &`                          |

## Pipelines

```powershell
# Pipe OBJECTS, not text
Get-ChildItem | Where-Object { $_.Length -gt 1MB } | Sort-Object Length -Descending

# $_ is the current pipeline object
Get-Process | Where-Object { $_.WorkingSet -gt 100MB } | Select-Object Name, Id, WorkingSet

# Simplified Where-Object syntax (PS 3.0+)
Get-Process | Where-Object WorkingSet -gt 100MB

# ForEach-Object for iteration
1..10 | ForEach-Object { $_ * 2 }
ls *.txt | ForEach-Object { "Processing $_" }

# Multi-line pipelines use backtick ` (not recommended) or pipe at line end
Get-ChildItem |
    Where-Object Length -gt 1MB |
    Sort-Object Name
```

## Filtering and Selecting

```powershell
# Where-Object — filter objects
Get-Process | Where-Object { $_.CPU -gt 10 }
Get-ChildItem | Where-Object Name -like "*.txt"

# Select-Object — pick properties or limit rows
Get-Process | Select-Object Name, Id, CPU
Get-Process | Select-Object -First 5
Get-Process | Select-Object -Last 10
Get-Process | Select-Object -Skip 5 -First 5

# Select-String — grep equivalent for text
Select-String -Path "*.log" -Pattern "ERROR"
Get-Content file.txt | Select-String "pattern"
```

## Common Patterns

```powershell
# Find files modified in last 7 days
Get-ChildItem -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) }

# Count lines of all .rs files
Get-ChildItem -Recurse -Filter *.rs | Get-Content | Measure-Object -Line

# Find large files
Get-ChildItem -Recurse | Where-Object Length -gt 10MB | Sort-Object Length -Descending

# Delete all .tmp files recursively
Get-ChildItem -Recurse -Filter *.tmp | Remove-Item

# Monitor a log file (like tail -f)
Get-Content -Path "app.log" -Tail 20 -Wait

# Check if command succeeded
if ($?) { "Success" } else { "Failed (exit code: $LASTEXITCODE)" }

# Loop with index
$items = @("a", "b", "c")
for ($i = 0; $i -lt $items.Count; $i++) {
    "$($i): $($items[$i])"
}

# Create multiple files
1..5 | ForEach-Object { New-Item -ItemType File -Name "file$_.txt" }

# Parse JSON
$data = Get-Content data.json | ConvertFrom-Json
$data.items[0].name

# Parse CSV
$rows = Import-Csv data.csv
$rows | Where-Object { $_.Status -eq "Active" }

# Export to JSON/CSV
Get-Process | Select-Object Name, Id | ConvertTo-Json | Out-File procs.json
Get-Process | Select-Object Name, Id | Export-Csv procs.csv
```

## Scripting

```powershell
# Parameters
param(
    [string]$Name,
    [int]$Count = 1,
    [switch]$Force
)

# Functions
function Get-Greeting {
    param([string]$Name = "World")
    "Hello, $Name!"
}

# If/else
if ($value -gt 10) {
    "Large"
} elseif ($value -gt 5) {
    "Medium"
} else {
    "Small"
}

# Switch
switch ($color) {
    "red"   { "Stop" }
    "green" { "Go" }
    default { "Unknown" }
}

# ForEach
foreach ($item in $collection) {
    "Item: $item"
}

# While
while ($count -gt 0) {
    $count--
}

# Try/catch
try {
    $result = 10 / 0
} catch {
    "Error: $_"
} finally {
    "Done"
}
```

## Comparison Operators

```powershell
-eq         # Equal
-ne         # Not equal
-gt         # Greater than
-lt         # Less than
-ge         # Greater or equal
-le         # Less or equal
-like       # Wildcard match (*, ?)
-notlike    # Wildcard non-match
-match      # Regex match
-notmatch   # Regex non-match
-contains   # Collection contains value
-in         # Value is in collection
```

## Key Gotchas

1. **No `&&` or `||`** — use `;` or `if ($?) { ... }`
2. **No `grep`/`sed`/`awk`** — use `Select-String`, `-replace`, `Where-Object`
3. **`$_` is current pipeline object**, not `$it` or `$in`
4. **Environment variables need `$env:` prefix** — `$env:PATH`, not `$PATH`
5. **Comparison uses `-eq`, not `=` or `==`** — `if ($a -eq 5)`
6. **Strings in double quotes** expand variables (`"Hello $name"`); single quotes don't
7. **Case-insensitive by default** — `"HELLO" -eq "hello"` is `$true`
8. **Backtick `` ` `` is escape/continuation**, not backslash
9. **No `#!/bin/pwsh` shebang needed** for .ps1 files
10. **`$LASTEXITCODE` for external programs**, `$?` for cmdlets
11. **`Measure-Object` replaces `wc`** — use `-Line`, `-Word`, `-Character` parameters
12. **No heredocs** — use here-strings: `@" ... "@` or `@' ... '@`

Related Skills

write-a-skill

15
from ifiokjr/oh-pi

Create new agent skills with proper structure, progressive disclosure, and bundled resources. Use when user wants to create, write, or build a new skill.

web-search

15
from ifiokjr/oh-pi

Web search via DuckDuckGo. Use when the user needs to look up current information online.

web-fetch

15
from ifiokjr/oh-pi

Fetch a web page and extract readable text content. Use when user needs to retrieve or read a web page.

rust-workspace-bootstrap

15
from ifiokjr/oh-pi

Scaffold a production-ready Rust workspace with knope changesets, devenv, and GitHub Actions CI/release workflows. Use when starting a new Rust project or monorepo.

request-refactor-plan

15
from ifiokjr/oh-pi

Create a detailed refactor plan with tiny commits via user interview, then file it as a GitHub issue. Use when user wants to plan a refactor, create a refactoring RFC, or break a refactor into safe incremental steps.

quick-setup

15
from ifiokjr/oh-pi

Detect project type and generate .pi/ configuration. Use when setting up pi for a new project or when user asks to initialize pi config.

nushell

15
from ifiokjr/oh-pi

Nushell syntax reference for shell commands — variables, pipelines, tables, custom commands, control flow, Bash-to-Nu equivalents, and common gotchas

neubrutalism

15
from ifiokjr/oh-pi

Neubrutalism design system skill. Use when building bold UI with thick borders, offset solid shadows, high saturation colors, and minimal border radius.

liquid-glass

15
from ifiokjr/oh-pi

Apple Liquid Glass design system. Use when building UI with translucent, depth-aware glass morphism following Apple's design language. Provides CSS tokens, component patterns, dark/light mode, and animation specs.

improve-codebase-architecture

15
from ifiokjr/oh-pi

Explore a codebase to find opportunities for architectural improvement, focusing on making the codebase more testable by deepening shallow modules. Use when user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more AI-navigable.

grill-me

15
from ifiokjr/oh-pi

Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".

glassmorphism

15
from ifiokjr/oh-pi

Glassmorphism design system skill. Use when building frosted-glass UI components with blur, transparency, and layered depth effects.