搜索

PythonReactSEOPDF
OpenClaw

powershell-safe-chain

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

dalomeve0 来源安装数☆ 0 仓库 Stars

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

SkillHub CLI

skillhub install dalomeve/powershell-safe-chain

打开来源仓库,查看说明和兼容环境后,按来源提供的命令或步骤安装。

将来源链接提供给你的 Agent,让它先读取说明、核对依赖,并向你说明将执行的安装步骤。

查看来源 ↗使用指南

技能说明

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:

mkdir test && cd test && echo done

Right:

$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
# 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
$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
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.

来源信息

Source
github
Repository
openclaw/skills
Path
skills/dalomeve/powershell-safe-chain
Version
—
Commit
ac05f94676d9cda258a57025b7820fdb82748823
分类来源
rules
状态
active
可见性
public

这些信息来自收录时的来源分析,可能滞后;使用前请核对最新来源文件。

来源内容

SKILL.md
# 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.**

相关技能

OpenClaw

1password

daggerkun007

Set up and use 1Password CLI (op). Use when installing the CLI, enabling desktop app integration, signing in (single or multi-account), or reading/injecting/running secrets via op.