agent-powershell-guidelines

Guides AI agents in executing PowerShell commands and file I/O safely on Windows.

Updated Aug 25, 2026
One-click install
npx skills add https://github.com/hyvanmielenpelit/SharedAgentSkills --skill agent-powershell-guidelines-hyvanmielenpelit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: agent-powershell-guidelines
Source: https://github.com/hyvanmielenpelit/SharedAgentSkills/tree/main/skills/agent-powershell-guidelines
Command: npx skills add https://github.com/hyvanmielenpelit/SharedAgentSkills --skill agent-powershell-guidelines-hyvanmielenpelit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? AI agents running shell commands on Windows frequently corrupt files, hang on interactive prompts, or hit parse errors because Windows PowerShell 5.1 behaves differently from Unix shells and PowerShell 7. This Skill prevents encoding corruption, silent failures, and blocked tool calls by encoding measured, verified rules for the Windows shell environment. ## Core Features & Use Cases - PowerShell 5.1 Parser Limits: Documents which constructs (&&, ||, ternary, null-coalescing, ?.) are parse errors or silently wrong, with correct replacements. - Safe File I/O: Provides .NET-based patterns for BOM-less UTF-8 reads/writes, CRLF/LF line-ending handling, and in-place text replacement without redirection operators. - Native Command & Hang Prevention: Covers $LASTEXITCODE checks, stderr redirect crashes, non-interactive execution rules, and Unix-to-PowerShell command equivalents. - Use Case: An agent needs to edit a JSON config file on Windows. Instead of piping ConvertTo-Json to Set-Content (which truncates nested objects at depth 2 and adds a BOM), it follows the Skill's pattern: ConvertTo-Json -Depth 100 written via [System.IO.File]::WriteAllText with UTF8Encoding($false). ## Quick Start Apply the PowerShell guidelines whenever you run terminal commands or write files on Windows, and follow its encoding and quoting rules for every command you execute.

Frequently Asked Questions about agent-powershell-guidelines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write UTF-8 files without BOM in PowerShell 5.1?

Use .NET methods instead of redirection or Set-Content: create a UTF8Encoding object with $false and call [System.IO.File]::WriteAllText with an absolute path. Redirection operators produce UTF-16 LE or UTF-8 with BOM depending on session state.

Why does my PowerShell script fail with '&&' or '||' operators?

Windows PowerShell 5.1 does not support && or || and throws a parse error before any line executes. Replace them with sequential statements and if ($?) or if (-not $?) checks; these operators only work in PowerShell 7.

How do I check if a native command like dotnet build failed in PowerShell?

Check $LASTEXITCODE immediately after the command, since $ErrorActionPreference = 'Stop' does not halt on native executable failures. Throw explicitly when the exit code is non-zero to surface the failure.

Why does ConvertTo-Json truncate my nested JSON objects?

ConvertTo-Json in PowerShell 5.1 defaults to a serialization depth of 2, silently replacing deeper objects with the string System.Collections.Hashtable. Always pass -Depth 100 and write the result with .NET methods to avoid BOM insertion.

Can I use grep or head to check line endings on Windows?

No. MSYS and WSL versions of grep, head, and file open files in text mode and strip CR in memory, reporting LF for CRLF files with no error. Count 0x0D and 0x0A bytes via .NET or use git ls-files --eol instead.

Why does my PowerShell command hang instead of failing?

Agent shells have no usable stdin, so commands like Read-Host, git commit without -m, or interactive pagers block until the tool times out. Use non-interactive flags, -Confirm:$false, and git --no-pager for read operations.