powershell-modernizer

Convert PowerShell 5.1 legacy scripts to PowerShell 7+ modern syntax and parallel execution.

Updated Feb 8, 2026
One-click install
npx skills add https://github.com/MartiXDev/ai-dev-strategy --skill powershell-modernizer-martixdev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: powershell-modernizer
Source: https://github.com/MartiXDev/ai-dev-strategy/tree/main/custom/PowerShell/skills/powershell-modernizer
Command: npx skills add https://github.com/MartiXDev/ai-dev-strategy --skill powershell-modernizer-martixdev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Legacy PowerShell 5.1 scripts use verbose if/else blocks, manual null checks, and sequential processing that miss the performance and readability gains available in PowerShell 7+. This Skill systematically transforms that legacy code into modern syntax without changing behavior. ## Core Features & Use Cases - Syntax Modernization: Converts verbose if/else assignments to ternary operators, null checks to null coalescing (??, ??=), and sequential command flows to pipeline chains (&&, ||). - Performance Upgrades: Adds ForEach-Object -Parallel with throttle limits for I/O-bound operations and cross-platform path handling using Join-Path and automatic variables like $IsWindows. - Validation Workflow: Verifies modernized scripts with PSParser tokenization, PSScriptAnalyzer, and behavior comparison against the original. - Use Case: You inherit a server-monitoring script written for Windows PowerShell 5.1. Use this Skill to rewrite it with parallel connection testing, ternary status assignments, and cross-platform log paths, then validate the output matches the original. ## Quick Start Modernize the attached LegacyScript.ps1 to PowerShell 7+ syntax and verify the behavior matches the original.

Frequently Asked Questions about powershell-modernizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert PowerShell 5.1 scripts to PowerShell 7?

Identify legacy patterns like verbose if/else assignments and manual null checks, then replace them with ternary operators, null coalescing (??=), and pipeline chains (&&, ||). Validate the result with PSScriptAnalyzer and compare behavior against the original script.

When should I use ForEach-Object -Parallel in PowerShell?

Use -Parallel for independent, I/O-bound operations like network calls, API requests, or multi-file processing where it can be up to 10x faster. Avoid it for ordered processing, shared state without $using: scope, or very fast operations under 10ms.

Does PowerShell 7 ternary operator work on Windows PowerShell 5.1?

No, the ternary operator (? :) requires PowerShell 7 or later. Scripts modernized with ternary, null coalescing, or pipeline chain operators will fail with syntax errors on Windows PowerShell 5.1.

How do I make PowerShell scripts cross-platform for Linux and macOS?

Replace hardcoded paths with Join-Path and use automatic variables like $IsWindows, $IsLinux, $IsMacOS, $HOME, and $PSScriptRoot. Use [Environment]::GetFolderPath() for system directories instead of literal paths like C:\Logs.

When should I avoid ternary operators in PowerShell?

Avoid ternary operators for complex multi-line logic, side effects in branches, and nested conditions, since they hurt readability. If a ternary expression needs an explanatory comment, use a standard if/else block instead.