PowerShell Patterns for Development
Critical Pitfalls
Templates with {{ }} — NEVER use Set-Content or heredocs
PowerShell interprets {{ }} as variable interpolation. Use the agent's create_file
tool for any file containing {{ }}, ${{}}, or Angular syntax.
# ❌ NEVER:
Set-Content file.html @"<div>{{ title }}</div>"@
# ✅ Always: agent create_file tool
# Editing existing files: replace_string_in_file
# Commands WITHOUT {{ }}: Set-Content with single quotes works fine
nvm-windows
nvm install X.Y.Zdoes NOT auto-activate →nvm use X.Y.Zis mandatorynvm listshows installed versions,*= active- Global packages (
@angular/cli) are NOT migrated between versions - Requires Admin shell — run PowerShell as Administrator
@angular/cli@22→ Node^22.22.3 || ^24.15.0 || >=26.0.0
Chaining — NEVER &&
&& is not valid in PowerShell 5.1:
npm install; npm run build # OK
npm install # Better: separate commands
npm run build
Execution Policy
Windows 11/10 default to Restricted — .ps1 scripts won't execute.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned # Requires admin
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser # Without admin
Best Practices
- Native cmdlets not aliases:
Get-ChildItemnotls,Select-Stringnotfindstr - Quote paths:
"C:\Path With Spaces\file.txt" Select-Object -First Nto limit output2>$nullto suppress stderrTest-Pathbefore reading/writing- NEVER
Start-Sleep— the agent is notified when async commands finish Remove-Item -Forceto delete;Push-Location/Pop-Locationto navigate
File Operations Decision Table
| Task | Tool |
|---|---|
Create file with {{ }} |
Agent create_file |
| Edit existing file | replace_string_in_file |
| Multiple simultaneous edits | multi_replace_string_in_file |
| Simple script without templates | Set-Content with single quotes |
| Overwrite existing file | Remove-Item -Force → create_file |