powershellAvoid common PowerShell mistakes — output behavior, array traps, and comparison operator gotchas.
Install via ClawdBot CLI:
clawdbot install ivangdavila/powershellRequires:
return or Write-Outputreturn doesn't stop output — previous uncaptured expressions still outputWrite-Host bypasses pipeline — use for display only, not data$null to suppress — $null = SomeFunction[void] cast also suppresses — void@(Get-Item .) forces array$null, not empty array — check with if ($result) carefully@(1,2,3) | ForEach sends items one by one+= on array creates new array — slow in loops, use [System.Collections.ArrayList], is array operator — ,$item wraps single item in array-eq, -ne, -gt, -lt — not ==, !=, >, <-like with wildcards, -match with regex — both return bool-contains for array membership — $arr -contains $item, not $item -in $arr (though -in works too)-ceq, -cmatch for case-sensitive$null on left side — $null -eq $var prevents array comparison issues"Hello $name" expands variable'$name' stays as literal text"Count: $($arr.Count)" for properties/methods@" ... "@ or @' ... '@ n ` for newline, t `` for tab$_ or $PSItem is current object — same thing, $_ more commonForEach-Object for pipeline — foreach statement doesn't take pipeline-PipelineVariable saves intermediate — Get-Service -PV svc | Where ...$ErrorActionPreference sets default — Stop, Continue, SilentlyContinue-ErrorAction Stop per command — makes non-terminating errors terminatingtry/catch only catches terminating — set ErrorAction Stop first$? is last command success — $LASTEXITCODE for native commands{ in if — if($x){ works but if ($x) { preferred= is assignment in conditions — use -eq for comparisonreturn ,@($arr) to keep arrayGet-Content returns lines array — -Raw for single stringSelect-Object creates new object — properties are copies, not referencespwsh is PowerShell 7+ — powershell is Windows PowerShell 5.1/ or \ — Join-Path for portable$env:VAR — works on all platformsls, cat may not exist, use full cmdlet namesGenerated Mar 1, 2026
Use PowerShell to monitor server health by checking disk space, service status, and event logs across Windows and Linux systems. Avoid array traps when processing multiple servers by forcing arrays with @() and handle errors with try/catch and ErrorAction Stop to ensure reliable alerts.
Script data migration between databases or file systems using PowerShell's pipeline for efficient streaming and string handling for log generation. Prevent output leaks by suppressing commands with [void] and use comparison operators like -eq for conditional logic to validate data integrity.
Deploy and configure software on mixed OS environments (Windows, Linux, macOS) using PowerShell 7+ with pwsh. Utilize Join-Path for portable paths and handle environment variables via $env:VAR, while avoiding common mistakes like using = instead of -eq in conditions.
Audit security settings and compliance policies across networks by scripting checks with PowerShell. Leverage array gotchas to properly handle single or null results and use -match for regex-based pattern matching in logs, ensuring accurate reporting with error handling via $ErrorActionPreference.
Offer subscription-based IT management using PowerShell scripts for automated monitoring, patching, and troubleshooting. Revenue comes from monthly fees per device or user, with scalability through reusable scripts that avoid common pitfalls like array unrolling and output leaks.
Develop and sell PowerShell-based tools or modules for specific industries like data migration or security auditing. Revenue is generated through one-time purchases or licensing fees, with cross-platform compatibility ensured by following best practices like using pwsh and portable paths.
Provide consulting services to help businesses implement PowerShell solutions, along with training workshops to teach best practices. Revenue streams include hourly rates for consulting and fixed fees for training sessions, focusing on avoiding common mistakes like comparison operator errors.
💬 Integration Tip
Integrate PowerShell with existing CI/CD pipelines by using pwsh for cross-platform scripts and handling errors with try/catch to ensure robust automation.
Remote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
Command-line tool to manage Google Workspace services including Gmail, Calendar, Drive, Sheets, Docs, Slides, Contacts, Tasks, People, Groups, and Keep.
Runs shell commands inside a dedicated tmux session named claw, captures, and returns the output, with safety checks for destructive commands.
A modern text-based browser. Renders web pages in the terminal using headless Firefox.
Write robust, portable shell scripts. Use when parsing arguments, handling errors properly, writing POSIX-compatible scripts, managing temp files, running commands in parallel, managing background processes, or adding --help to scripts.
NotebookLM CLI wrapper via `node {baseDir}/scripts/notebooklm.mjs`. Use for auth, notebooks, chat, sources, notes, sharing, research, and artifact generation/download.