powershell-7-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePowerShell 7 Expert
PowerShell 7 专家
Purpose
用途
Provides expertise in modern PowerShell 7+ (PowerShell Core) for cross-platform automation. Specializes in parallel processing, REST API integration, modern scripting patterns, and leveraging new language features.
提供适用于跨平台自动化的现代PowerShell 7+(PowerShell Core)专业知识。专注于并行处理、REST API集成、现代脚本编写模式以及新语言特性的运用。
When to Use
适用场景
- Cross-platform automation (Windows, Linux, macOS)
- Parallel processing with ForEach-Object -Parallel
- REST API integrations
- Modern PowerShell scripting patterns
- Pipeline chain operators (&& ||)
- Ternary expressions and null coalescing
- SSH-based remoting
- JSON/YAML data manipulation
- 跨平台自动化(Windows、Linux、macOS)
- 使用ForEach-Object -Parallel进行并行处理
- REST API集成
- 现代PowerShell脚本编写模式
- 管道链运算符(&& ||)
- 三元表达式和空合并运算符
- 基于SSH的远程管理
- JSON/YAML数据处理
Quick Start
快速开始
Invoke this skill when:
- Writing cross-platform PowerShell scripts
- Using PowerShell 7+ specific features
- Implementing parallel processing
- Building REST API integrations
- Modernizing scripts from 5.1
Do NOT invoke when:
- Legacy Windows-only systems → use
/powershell-5.1-expert - GUI development → use
/powershell-ui-architect - Security configuration → use
/powershell-security-hardening - Module design → use
/powershell-module-architect
触发此技能的场景:
- 编写跨平台PowerShell脚本
- 使用PowerShell 7+专属特性
- 实现并行处理
- 构建REST API集成
- 将脚本从5.1版本现代化
请勿触发此技能的场景:
- 仅支持Windows的旧系统 → 使用
/powershell-5.1-expert - GUI开发 → 使用
/powershell-ui-architect - 安全配置 → 使用
/powershell-security-hardening - 模块设计 → 使用
/powershell-module-architect
Decision Framework
决策框架
PowerShell 7 Feature Selection?
├── Parallel Processing
│ ├── Simple iteration → ForEach-Object -Parallel
│ └── Complex workflows → Start-ThreadJob
├── API Integration
│ └── Invoke-RestMethod with modern options
├── Null Handling
│ ├── Default value → ?? operator
│ └── Conditional access → ?. operator
└── Pipeline Control
└── && and || chain operatorsPowerShell 7 Feature Selection?
├── Parallel Processing
│ ├── Simple iteration → ForEach-Object -Parallel
│ └── Complex workflows → Start-ThreadJob
├── API Integration
│ └── Invoke-RestMethod with modern options
├── Null Handling
│ ├── Default value → ?? operator
│ └── Conditional access → ?. operator
└── Pipeline Control
└── && and || chain operatorsCore Workflows
核心工作流
1. Parallel Processing
1. 并行处理
- Identify parallelizable workload
- Use ForEach-Object -Parallel
- Set -ThrottleLimit appropriately
- Handle thread-safe data access
- Aggregate results
- Handle errors from parallel runs
- 识别可并行化的工作负载
- 使用ForEach-Object -Parallel
- 合理设置-ThrottleLimit参数
- 处理线程安全的数据访问
- 聚合结果
- 处理并行运行中的错误
2. REST API Integration
2. REST API集成
- Construct request parameters
- Handle authentication (Bearer, OAuth)
- Use Invoke-RestMethod
- Parse JSON response
- Implement pagination
- Add retry logic for failures
- 构造请求参数
- 处理身份验证(Bearer、OAuth)
- 使用Invoke-RestMethod
- 解析JSON响应
- 实现分页逻辑
- 为失败请求添加重试机制
3. Cross-Platform Script
3. 跨平台脚本编写
- Avoid Windows-specific paths
- Use $PSVersionTable and $IsLinux/$IsWindows
- Handle path separators correctly
- Test on all target platforms
- Use compatible modules
- Document platform requirements
- 避免使用Windows专属路径
- 使用$PSVersionTable和$IsLinux/$IsWindows变量
- 正确处理路径分隔符
- 在所有目标平台上进行测试
- 使用兼容的模块
- 记录平台要求
Best Practices
最佳实践
- Use ternary operator for concise conditionals
- Leverage null-coalescing for defaults
- Use ForEach-Object -Parallel for CPU-bound tasks
- Prefer SSH remoting over WinRM for cross-platform
- Use Join-Path for cross-platform paths
- Test on all target operating systems
- 使用三元运算符编写简洁的条件判断
- 利用空合并运算符设置默认值
- 对CPU密集型任务使用ForEach-Object -Parallel
- 跨平台场景下优先使用SSH远程管理而非WinRM
- 使用Join-Path处理跨平台路径
- 在所有目标操作系统上进行测试
Anti-Patterns
反模式
| Anti-Pattern | Problem | Correct Approach |
|---|---|---|
| Hardcoded backslashes | Breaks on Linux/macOS | Join-Path or / |
| Windows-only cmdlets | Cross-platform failure | Check availability |
| Over-parallelization | Thread overhead | Tune ThrottleLimit |
| Ignoring $Error | Silent failures | Proper error handling |
| Assuming WinRM | Not cross-platform | SSH remoting |
| 反模式 | 问题 | 正确做法 |
|---|---|---|
| 硬编码反斜杠 | 在Linux/macOS上运行失败 | 使用Join-Path或/ |
| 仅支持Windows的cmdlet | 跨平台运行失败 | 检查可用性 |
| 过度并行化 | 线程开销过大 | 调整ThrottleLimit参数 |
| 忽略$Error | 静默失败 | 正确处理错误 |
| 依赖WinRM | 不支持跨平台 | 使用SSH远程管理 |