powershell-safe-invocation

Write and run PowerShell commands with safe argument passing, quoting, and process invocation.

Updated Jun 8, 2026
One-click install
npx skills add https://github.com/Type3limit/TypeAxSkills --skill powershell-safe-invocation-type3limit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: powershell-safe-invocation
Source: https://github.com/Type3limit/TypeAxSkills/tree/main/powershell-safe-invocation
Command: npx skills add https://github.com/Type3limit/TypeAxSkills --skill powershell-safe-invocation-type3limit

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Generated PowerShell commands often break when quotes, paths with spaces, JSON, or nested shells are involved, causing corrupted arguments, silent failures, or unsafe file operations. This Skill provides rules and patterns for invoking native programs, cmdlets, and scripts on Windows without escaping bugs or destructive mistakes. ## Core Features & Use Cases - Safe native invocation: Pass arguments as arrays with & $exe @args, capture $LASTEXITCODE correctly, and avoid Invoke-Expression, cmd.exe /c wrappers, and Bash-style escaping. - Structured cmdlet usage: Apply hashtable splatting, -LiteralPath, terminating errors, and explicit encoding for reliable file operations. - Complex command handling: Move multiline or nested-quote logic into temporary .ps1 files run via pwsh.exe -NoLogo -NoProfile -NonInteractive -File, and use ProcessStartInfo.ArgumentList when exact argument boundaries or stdout/stderr capture are required. - Use Case: An agent must run a tool at C:\Program Files\App\tool.exe with a JSON input path containing spaces. Instead of building one quoted command string, it writes a small .ps1 script using an argument array and runs it with pwsh.exe -File, avoiding quoting corruption. ## Quick Start Use the powershell-safe-invocation skill to rewrite this command so it safely runs a native executable with a path containing spaces.

Frequently Asked Questions about powershell-safe-invocation

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

FAQPage Schema
How do I pass arguments with spaces to a native executable in PowerShell?

Build an array where each argument is one element, then invoke with & $exe @args. This preserves exact argument boundaries, including empty strings, without manual quoting or escaping.

What is the difference between pwsh.exe and powershell.exe?

pwsh.exe is PowerShell 7, while powershell.exe is Windows PowerShell 5.1, and both can be installed side by side. Verify the active shell with $PSVersionTable and $PSNativeCommandArgumentPassing.

Should I use Start-Process or the call operator to run a program?

Use & $exe @args for normal foreground execution. Reserve Start-Process for elevation, new or hidden windows, detached launch, or shell behavior, since its -ArgumentList joins values into one string.

Why does my PowerShell command fail when nested inside cmd.exe?

Each layer (cmd.exe, -Command strings, JSON escaping) reinterprets quotes, backslashes, and dollar signs, corrupting arguments. Write the logic to a .ps1 file and run it with pwsh.exe -NoLogo -NoProfile -NonInteractive -File instead.

When should I use Invoke-Expression in PowerShell scripts?

Avoid Invoke-Expression for launching programs; use & $exe @args instead. Use it only when trusted text intentionally contains PowerShell source code and no structured alternative exists, never with untrusted input.

How do I safely delete files recursively in PowerShell?

Resolve the absolute root and target paths, verify the target starts with the root plus a directory separator, and reject empty, root-level, or unexpected paths before calling Remove-Item -Recurse.