Ensures cross-version PowerShell stability by managing parameter passing, quoting, and environment differences.
Install
mkdir -p .claude/skills/pwsh && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/15430" && unzip -o skill.zip -d .claude/skills/pwsh && rm skill.zipInstalls to .claude/skills/pwsh
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
在 Windows PowerShell 5.1 与 PowerShell 7 中编写和执行稳定命令,重点处理引号、管道符、原生命令参数传递与跨版本兼容。遇到 `--jq`/过滤表达式被 PowerShell 误解析、同一命令在 pwsh5 与 pwsh7 行为不一致、或需要为 pwsh7.3+ 增加参数传递适配时使用此 skill。Key capabilities
- →Confirm target PowerShell interpreter version
- →Generate PowerShell commands compatible with pwsh5
- →Adapt commands for pwsh7 exclusive syntax when detected
- →Assemble parameters using variables or arrays
- →Handle native command parameters to prevent misparsing
- →Output commands with compatibility prerequisites
How it works
The skill determines the PowerShell version, then generates commands prioritizing pwsh5 compatibility, adapting for pwsh7 features only when confirmed, and handling parameter passing for native commands.
Inputs & outputs
When to use pwsh
- →Run cross-platform scripts
- →Fix quoting issues with CLI tools
- →Migrate scripts to pwsh 7
- →Handle native argument passing
About this skill
Pwsh
Overview
以“先兼容、后增强”为原则生成 PowerShell 命令。默认先满足 pwsh5 可运行,再按需启用 pwsh7 专属能力。
Workflow
- 确认目标解释器:先读取
$PSVersionTable.PSVersion,判断是 5.1 还是 7.x。 - 选兼容级别:默认按 pwsh5 语法生成;仅在确认 7.x 时使用 7 专属语法。
- 组装参数:优先用变量或数组传参,避免在命令行内堆叠转义。
- 处理原生命令:当参数被误解析时,先改写引号;必要时使用
--%或 pwsh7 参数传递设置。 - 输出结果:明确命令、兼容前提、以及可能影响行为的版本差异。
Baseline Rules
- 将 pwsh5 视为最低兼容基线。
- 在 PowerShell 中向
--jq或类似参数传入含|的表达式时,必须使用单引号字符串。 - 需要变量拼接时,先构造变量再传参,不在命令行直接拼复杂引号。
- 文件读写显式指定编码,避免依赖不同版本默认值。
pwsh7 Adaptation
- 仅在确认
PowerShell 7.3+时考虑$PSNativeCommandArgumentPassing影响。 - 旧脚本因参数传递行为变化失败时,按需临时切换
Legacy,任务完成后恢复原值。 - 使用 pwsh7 专属语法(如
??、||、&&、ForEach-Object -Parallel)前先做版本判断。
Failure Handling
- 出现
|被吃掉:检查表达式是否被单引号包裹。 - 原生命令参数异常:先改为变量传参,再评估
--%或$PSNativeCommandArgumentPassing。 - 跨版本结果不同:回显版本号与关键变量值后,再给出兼容改写命令。
Output Format
Plan: 要解决的 PowerShell 兼容问题。Commands: 可直接执行的命令(必要时分 5.1 与 7.x 两套)。Result: 关键输出与版本信息。Compat: 是否依赖 pwsh7 特性,及回退方案。
Reference
按需加载,不要一次性读取全部细节:
- 通用兼容基线:
references/pwsh5-baseline.md --jq与引号规则:references/quoting-jq.md- pwsh7 增量适配:
references/pwsh7-adaptation.md
When not to use it
- →When the user is not working with PowerShell 5.1 or 7.x
- →When the user does not need cross-version compatibility for PowerShell commands
- →When the user wants to use PowerShell features not covered by the skill
Limitations
- →Default generation is based on pwsh5 syntax
- →pwsh7 exclusive syntax is used only when 7.x is confirmed
- →Requires explicit encoding for file read/write to avoid default value dependencies
How it compares
This workflow automatically handles cross-version compatibility and parameter escaping for PowerShell, reducing manual debugging of shell script differences.
Compared to similar skills
pwsh side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| pwsh (this skill) | 0 | 5mo | No flags | Intermediate |
| applescript | 28 | 8mo | Review | Advanced |
| bazel-build-optimization | 14 | 2mo | No flags | Advanced |
| home-assistant-manager | 9 | 8mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by BiFangKNT
View all by BiFangKNT →You might also like
applescript
martinholovsky
Expert in AppleScript and JavaScript for Automation (JXA) for macOS system scripting. Specializes in secure script execution, application automation, and system integration. HIGH-RISK skill due to shell command execution and system-wide control capabilities.
bazel-build-optimization
wshobson
Optimize Bazel builds for large-scale monorepos. Use when configuring Bazel, implementing remote execution, or optimizing build performance for enterprise codebases.
home-assistant-manager
komal-SkyNET
Expert-level Home Assistant configuration management with efficient deployment workflows (git and rapid scp iteration), remote CLI access via SSH and hass-cli, automation verification protocols, log analysis, reload vs restart optimization, and comprehensive Lovelace dashboard management for tablet-optimized UIs. Includes template patterns, card types, debugging strategies, and real-world examples.
swarm-advanced
ruvnet
Advanced swarm orchestration patterns for research, development, testing, and complex distributed workflows
windows-expert
jackspace
Expert guidance for Windows, PowerShell, WSL interop, and cross-platform development
bash-linux
davila7
Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.