主题
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
rgfor 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, andwc. 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, andsort. Use explicit executable names such asls.exeand inspectGet-Command ls -Allwhen 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
$LASTEXITCODEafter native commands; use-ErrorAction Stopor 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 $ScriptIf 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 SourceInterpretation:
PSVersion.Major -ge 7: continue in the current shell.- Current host is 5.1 but
pwshexists: switch future commands topwsh. - Current host is 5.1 and
pwshis 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 -InstallFallback when the helper is unavailable:
powershell
winget install --id Microsoft.PowerShell --source wingetAfter 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 -HealthOnlyTemporary 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 = $Utf8NoBomThis fallback reduces encoding issues but does not replace PowerShell 7. Continue to recommend pwsh for future AI-assisted development.