Skip to content

PowerShell 7 Environment Skill ​

Use this skill on Windows before command-heavy SCE/WasiCore work, especially for Chinese users. Windows PowerShell 5.1 often uses legacy console encodings and can corrupt UTF-8 Chinese output. Prefer PowerShell 7 (pwsh) for AI terminal commands, SDK setup scripts, builds, MCP helper scripts, and log inspection.

PowerShell 7 is a recommendation for command-heavy work, not a prerequisite for first-game setup, project refresh, resource statistics, or publishing. Keep these script entry points compatible with Windows PowerShell 5.1.

Choose The Tools ​

  • Recommend PowerShell 7 first for SCE scripts, Windows process management, JSON handling, and MCP helpers. Verify the AI terminal actually runs pwsh; installing it does not switch an existing shell.
  • Prefer rg for searching code and logs. Check whether the assistant already provides it before recommending installation.
  • Treat coreutils (GNU or uutils) as an optional addition for commands such as head, tail, and wc. It does not replace PowerShell or supply Bash syntax. Do not require it for SCE workflows.
  • PowerShell aliases can take precedence over coreutils commands such as ls, cat, cp, rm, and sort. Use explicit executable names such as ls.exe and inspect Get-Command ls -All when Unix-style options are needed.

Match Syntax To The Host ​

  • PowerShell 7 supports && and ||; Windows PowerShell 5.1 does not. A semicolon runs the next statement regardless of the previous command's success, so it is not an equivalent replacement for &&.
  • For 5.1-compatible scripts, check $LASTEXITCODE after native commands; use -ErrorAction Stop or check $? for PowerShell cmdlets before continuing dependent work.
  • Bash heredocs (<<'EOF') are not PowerShell syntax. PowerShell supports $(...) subexpressions, but their contents, quoting, and escaping follow PowerShell rules. Installing coreutils does not change these rules.

Detect The Current Host ​

If the project-local helper exists, run it first:

powershell
$Script = Join-Path (Get-Location) 'ai\tools\Ensure-PowerShell7.ps1'
if (-not (Test-Path -LiteralPath $Script)) {
    $Script = Join-Path (Get-Location) '.cursor\tools\Ensure-PowerShell7.ps1'
}
powershell -ExecutionPolicy Bypass -File $Script

If the helper is not available, use this inline check:

powershell
$PSVersionTable.PSVersion.ToString()
$PSVersionTable.PSEdition
Get-Command pwsh -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty Source

Interpretation:

  • PSVersion.Major -ge 7: continue in the current shell.
  • Current host is 5.1 but pwsh exists: switch future commands to pwsh.
  • Current host is 5.1 and pwsh is missing: tell the user PowerShell 7 is recommended because PowerShell 5.1 can break UTF-8 Chinese output, then offer installation help.

Install PowerShell 7 ​

Do not install software silently. If the user already asked for setup or agrees to install, prefer the helper:

powershell
powershell -ExecutionPolicy Bypass -File .\ai\tools\Ensure-PowerShell7.ps1 -Install

Fallback when the helper is unavailable:

powershell
winget install --id Microsoft.PowerShell --source winget

After installation, verify:

powershell
pwsh -NoLogo -NoProfile -Command '$PSVersionTable.PSVersion.ToString()'

If pwsh was just installed but is not found in the same terminal, ask the user to restart the terminal or IDE, then verify again. For direct script calls, prefer:

powershell
pwsh -NoLogo -NoProfile -ExecutionPolicy Bypass -File .\ai\tools\Invoke-SceMcp.ps1 -HealthOnly

Temporary PowerShell 5.1 Fallback ​

If PowerShell 7 cannot be installed immediately, set UTF-8 for the current session before reading Chinese logs or running SDK scripts:

powershell
chcp 65001 > $null
$Utf8NoBom = [System.Text.UTF8Encoding]::new($false)
$OutputEncoding = $Utf8NoBom
[Console]::InputEncoding = $Utf8NoBom
[Console]::OutputEncoding = $Utf8NoBom

This fallback reduces encoding issues but does not replace PowerShell 7. Continue to recommend pwsh for future AI-assisted development.