返回顶部
p

powershell-safe-chain

Chain PowerShell commands safely without &&. Use try/catch, ErrorAction, and proper sequencing for reliable Windows execution.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
357
下载量
0
收藏
概述
安装方式
版本历史

powershell-safe-chain

# PowerShell Safe Chain Chain commands reliably on Windows PowerShell. No `&&` anti-patterns. ## Problem PowerShell differs from bash: - `&&` does NOT work for command chaining - Parameter parsing is case-insensitive but strict - Errors continue by default (no fail-fast) - Path separators vary (`\` vs `/`) ## Workflow ### 1. Safe Chaining Pattern **Wrong**: ```powershell mkdir test && cd test && echo done ``` **Right**: ```powershell $ErrorActionPreference = 'Stop' try { New-Item -ItemType Directory -Path test -Force Set-Location test Write-Host 'done' } catch { Write-Error "Failed at step: $_" exit 1 } ``` ### 2. Conditional Chaining ```powershell # If-then pattern if (Test-Path $file) { Remove-Item $file Write-Host "Deleted" } else { Write-Warning "File not found" } # Pipeline with error handling Get-Process | Where-Object CPU -GT 100 | Stop-Process -WhatIf ``` ### 3. Splatting for Complex Commands ```powershell $params = @{ Path = $filePath Encoding = 'UTF8' Force = $true } Set-Content @params ``` ## Executable Completion Criteria | Criteria | Verification | |----------|-------------| | No `&&` in scripts | `Select-String '&&' *.ps1` returns nothing | | ErrorAction set | `Select-String 'ErrorAction' *.ps1` matches | | try/catch present | `Select-String 'try|catch' *.ps1` matches | | Paths use Join-Path | `Select-String 'Join-Path' *.ps1` matches | ## Privacy/Safety - No hardcoded credentials - Use `[SecureString]` for passwords - Environment variables via `$env:VAR` ## Self-Use Trigger Use when: - Writing any PowerShell script - Chaining 2+ commands - Executing file operations --- **Chain safely. Fail explicitly.**

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 powershell-safe-chain-1776287513 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 powershell-safe-chain-1776287513 技能

通过命令行安装

skillhub install powershell-safe-chain-1776287513

下载 Zip 包

⬇ 下载 powershell-safe-chain v1.0.0

文件大小: 1.64 KB | 发布时间: 2026-4-16 17:47

v1.0.0 最新 2026-4-16 17:47
Initial release introducing safe command chaining patterns for PowerShell:

- Explains why `&&` shouldn't be used for command chaining in PowerShell.
- Provides recommended patterns using `try/catch`, `ErrorActionPreference`, and conditionals.
- Shows splatting for clean parameter handling in complex commands.
- Lists criteria for executable script safety and compliance.
- Adds privacy and safety best practices for credentials and environment variables.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部