powershell-7-expert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PowerShell 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 operators
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 operators

Core Workflows

核心工作流

1. Parallel Processing

1. 并行处理

  1. Identify parallelizable workload
  2. Use ForEach-Object -Parallel
  3. Set -ThrottleLimit appropriately
  4. Handle thread-safe data access
  5. Aggregate results
  6. Handle errors from parallel runs
  1. 识别可并行化的工作负载
  2. 使用ForEach-Object -Parallel
  3. 合理设置-ThrottleLimit参数
  4. 处理线程安全的数据访问
  5. 聚合结果
  6. 处理并行运行中的错误

2. REST API Integration

2. REST API集成

  1. Construct request parameters
  2. Handle authentication (Bearer, OAuth)
  3. Use Invoke-RestMethod
  4. Parse JSON response
  5. Implement pagination
  6. Add retry logic for failures
  1. 构造请求参数
  2. 处理身份验证(Bearer、OAuth)
  3. 使用Invoke-RestMethod
  4. 解析JSON响应
  5. 实现分页逻辑
  6. 为失败请求添加重试机制

3. Cross-Platform Script

3. 跨平台脚本编写

  1. Avoid Windows-specific paths
  2. Use $PSVersionTable and $IsLinux/$IsWindows
  3. Handle path separators correctly
  4. Test on all target platforms
  5. Use compatible modules
  6. Document platform requirements
  1. 避免使用Windows专属路径
  2. 使用$PSVersionTable和$IsLinux/$IsWindows变量
  3. 正确处理路径分隔符
  4. 在所有目标平台上进行测试
  5. 使用兼容的模块
  6. 记录平台要求

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-PatternProblemCorrect Approach
Hardcoded backslashesBreaks on Linux/macOSJoin-Path or /
Windows-only cmdletsCross-platform failureCheck availability
Over-parallelizationThread overheadTune ThrottleLimit
Ignoring $ErrorSilent failuresProper error handling
Assuming WinRMNot cross-platformSSH remoting
反模式问题正确做法
硬编码反斜杠在Linux/macOS上运行失败使用Join-Path或/
仅支持Windows的cmdlet跨平台运行失败检查可用性
过度并行化线程开销过大调整ThrottleLimit参数
忽略$Error静默失败正确处理错误
依赖WinRM不支持跨平台使用SSH远程管理