返回顶部
p

powershell-safe-chainPowerShell安全链

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

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

powershell-safe-chain

技能名称:powershell-safe-chain
详细描述:

PowerShell 安全链

在 Windows PowerShell 中可靠地链式执行命令。避免使用 && 反模式。

问题

PowerShell 与 bash 不同:

  • - && 不适用于命令链式执行
  • 参数解析不区分大小写但严格
  • 默认情况下错误会继续执行(无快速失败机制)
  • 路径分隔符不同(\ 与 /)

工作流程

1. 安全链式模式

错误示例
powershell
mkdir test && cd test && echo done

正确示例
powershell
$ErrorActionPreference = Stop
try {
New-Item -ItemType Directory -Path test -Force
Set-Location test
Write-Host done
} catch {
Write-Error 在步骤处失败: $_
exit 1
}

2. 条件链式执行

powershell

If-then 模式


if (Test-Path $file) {
Remove-Item $file
Write-Host 已删除
} else {
Write-Warning 文件未找到
}

带错误处理的管道

Get-Process | Where-Object CPU -GT 100 | Stop-Process -WhatIf

3. 使用散列参数传递复杂命令

powershell
$params = @{
Path = $filePath
Encoding = UTF8
Force = $true
}
Set-Content @params

可执行完成标准

| 标准 | 验证方法 |
|----------|-------------|
| 脚本中无 && | Select-String && *.ps1 返回空 |
| 设置 ErrorAction | Select-String ErrorAction *.ps1 匹配 |
| 包含 try/catch | Select-String try|catch *.ps1 匹配 |
| 路径使用 Join-Path | Select-String Join-Path *.ps1 匹配 |

隐私/安全

  • - 无硬编码凭据
  • 密码使用 [SecureString]
  • 通过 $env:VAR 使用环境变量

自我使用触发条件

在以下情况下使用:

  • - 编写任何 PowerShell 脚本时
  • 链式执行 2 个以上命令时
  • 执行文件操作时



安全链式执行。明确失败。

标签

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

下载

⬇ 下载 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-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部