Loading...
Loading...
Compare original and translation side by side
Critical patterns and pitfalls for Windows PowerShell.
Windows PowerShell的关键使用模式与常见陷阱。
| ❌ Wrong | ✅ Correct |
|---|---|
| |
| |
| ❌ 错误写法 | ✅ 正确写法 |
|---|---|
| |
| |
| Purpose | ❌ Don't Use | ✅ Use |
|---|---|---|
| Success | ✅ ✓ | [OK] [+] |
| Error | ❌ ✗ 🔴 | [!] [X] |
| Warning | ⚠️ 🟡 | [*] [WARN] |
| Info | ℹ️ 🔵 | [i] [INFO] |
| Progress | ⏳ | [...] |
| 用途 | ❌ 禁止使用 | ✅ 推荐使用 |
|---|---|---|
| 成功 | ✅ ✓ | [OK] [+] |
| 错误 | ❌ ✗ 🔴 | [!] [X] |
| 警告 | ⚠️ 🟡 | [*] [WARN] |
| 信息 | ℹ️ 🔵 | [i] [INFO] |
| 进度 | ⏳ | [...] |
| ❌ Wrong | ✅ Correct |
|---|---|
| |
| |
| ❌ 错误写法 | ✅ 正确写法 |
|---|---|
| |
| |
| ❌ Wrong | ✅ Correct |
|---|---|
| Store in variable first |
$value = $obj.prop.sub
Write-Output "Value: $value"| ❌ 错误写法 | ✅ 正确写法 |
|---|---|
| 先存储到变量中 |
$value = $obj.prop.sub
Write-Output "Value: $value"| Value | Use |
|---|---|
| Stop | Development (fail fast) |
| Continue | Production scripts |
| SilentlyContinue | When errors expected |
| 取值 | 适用场景 |
|---|---|
| Stop | 开发环境(快速失败) |
| Continue | 生产环境脚本 |
| SilentlyContinue | 预期会出现错误的场景 |
| Pattern | Use |
|---|---|
| Literal path | |
| Variable path | |
| Relative | |
| 模式 | 适用场景 |
|---|---|
| 字面路径 | |
| 变量路径 | |
| 相对路径 | |
| Operation | Syntax |
|---|---|
| Empty array | |
| Add item | |
| ArrayList add | `$list.Add($item) |
| 操作 | 语法 |
|---|---|
| 空数组 | |
| 添加元素 | |
| ArrayList添加元素 | `$list.Add($item) |
| ❌ Wrong | ✅ Correct |
|---|---|
| |
-Depth| ❌ 错误写法 | ✅ 正确写法 |
|---|---|
| |
-Depth| Operation | Pattern |
|---|---|
| Read | `Get-Content "file.json" -Raw |
| Write | `$data |
| 操作 | 模式 |
|---|---|
| 读取 | `Get-Content "file.json" -Raw |
| 写入 | `$data |
| Error Message | Cause | Fix |
|---|---|---|
| "parameter 'or'" | Missing parentheses | Wrap cmdlets in () |
| "Unexpected token" | Unicode character | Use ASCII only |
| "Cannot find property" | Null object | Check null first |
| "Cannot convert" | Type mismatch | Use .ToString() |
| 错误信息 | 原因 | 解决方法 |
|---|---|---|
| "parameter 'or'" | 缺少括号 | 用()包裹cmdlet |
| "Unexpected token" | 包含Unicode字符 | 仅使用ASCII字符 |
| "Cannot find property" | 对象为空 | 先检查空值 |
| "Cannot convert" | 类型不匹配 | 使用.ToString()方法 |
undefinedundefined
---
> **Remember:** PowerShell has unique syntax rules. Parentheses, ASCII-only, and null checks are non-negotiable.
---
> **注意:** PowerShell具有独特的语法规则。括号使用、仅ASCII字符、空值检查是必须遵守的要求。