$npx -y skills add comol/ai_rules_1c --skill powershell-windowsPowerShell scripting rules for Windows environment. Use when running shell commands, Docker operations, or HTTP requests on Windows PowerShell.
| 1 | # PowerShell Windows — Scripting Rules |
| 2 | |
| 3 | ## Core Principles |
| 4 | |
| 5 | ### 1. Command Separation |
| 6 | - Windows PowerShell 5.1 does not support `&&`; PowerShell 7 does. |
| 7 | - For independent commands use `;`: `Set-Location "path"; Get-ChildItem`. |
| 8 | - For dependent native commands preserve short-circuit semantics explicitly: |
| 9 | ```powershell |
| 10 | git add . |
| 11 | if ($LASTEXITCODE -eq 0) { git commit -m "message" } |
| 12 | ``` |
| 13 | |
| 14 | ### 2. Path Quoting |
| 15 | - **Always use double quotes** for paths with spaces: |
| 16 | ```powershell |
| 17 | cd "D:\My Projects\MyApp" |
| 18 | ``` |
| 19 | |
| 20 | ### 3. Script Execution |
| 21 | - For .bat/.cmd files: |
| 22 | ```powershell |
| 23 | ./gradlew clean build |
| 24 | .\gradlew.bat clean build |
| 25 | ``` |
| 26 | |
| 27 | ### 4. Docker Commands |
| 28 | - Specify full path to docker-compose files: |
| 29 | ```powershell |
| 30 | docker-compose -f "D:\My Projects\app\docker-compose.yml" up -d |
| 31 | ``` |
| 32 | |
| 33 | ### 5. HTTP Requests |
| 34 | - Prefer PowerShell-native HTTP so behavior does not depend on whether `curl` |
| 35 | resolves to an alias or `curl.exe`: |
| 36 | ```powershell |
| 37 | Invoke-WebRequest -Uri "http://localhost:9090/status" -UseBasicParsing |
| 38 | ``` |
| 39 | |
| 40 | ### 6. Waiting/Delays |
| 41 | - **Wrong**: `timeout 10` |
| 42 | - **Correct**: |
| 43 | ```powershell |
| 44 | Start-Sleep -Seconds 10 |
| 45 | ``` |
| 46 | |
| 47 | ### 7. JSON Handling |
| 48 | - JSON parsing: |
| 49 | ```powershell |
| 50 | $response = Invoke-WebRequest -Uri "http://localhost:9090/status" -UseBasicParsing |
| 51 | $json = $response.Content | ConvertFrom-Json |
| 52 | $json | ConvertTo-Json -Depth 3 |
| 53 | ``` |
| 54 | |
| 55 | ### 8. Process Checking |
| 56 | - Process search: |
| 57 | ```powershell |
| 58 | Get-Process -Name "java" -ErrorAction SilentlyContinue |
| 59 | ``` |
| 60 | |
| 61 | ### 9. Docker Operations |
| 62 | - Stop containers: |
| 63 | ```powershell |
| 64 | docker-compose -f "path\to\file.yml" down |
| 65 | ``` |
| 66 | - Build images: |
| 67 | ```powershell |
| 68 | docker-compose -f "path\to\file.yml" build --no-cache |
| 69 | ``` |
| 70 | |
| 71 | ### 10. Error Handling |
| 72 | - Ignore errors: |
| 73 | ```powershell |
| 74 | Get-Process -Name "java" -ErrorAction SilentlyContinue |
| 75 | ``` |
| 76 | |
| 77 | ## Common Errors and Fixes |
| 78 | |
| 79 | | Error | Cause | Fix | |
| 80 | |-------|-------|-----| |
| 81 | | `&& is not recognized` | Running Windows PowerShell 5.1 | Use `;` only for independent commands; use `$LASTEXITCODE` for conditional chaining | |
| 82 | | `curl` behaves unexpectedly | Windows PowerShell alias / executable resolution differs | Use `Invoke-WebRequest`, or call `curl.exe` explicitly when its CLI semantics are required | |
| 83 | | `timeout` behaves unexpectedly | Console utility semantics differ from shell sleep | Use `Start-Sleep` | |
| 84 | | `Path not found` | Missing quotes on spaced path | Wrap path in double quotes | |
| 85 | |
| 86 | ## Correct Command Examples |
| 87 | |
| 88 | ```powershell |
| 89 | # Change directory and execute command |
| 90 | cd "D:\My Projects\MyApp"; ./gradlew clean build -x test |
| 91 | |
| 92 | # Wait and make HTTP request |
| 93 | Start-Sleep -Seconds 10; Invoke-WebRequest -Uri "http://localhost:9090/status" -UseBasicParsing |
| 94 | |
| 95 | # Docker operations |
| 96 | docker-compose -f "D:\My Projects\MyApp\docker-compose.yml" down |
| 97 | docker-compose -f "D:\My Projects\MyApp\docker-compose.yml" build --no-cache |
| 98 | docker-compose -f "D:\My Projects\MyApp\docker-compose.yml" up -d |
| 99 | |
| 100 | # Check server status |
| 101 | $response = Invoke-WebRequest -Uri "http://localhost:9090/status" -UseBasicParsing |
| 102 | $json = $response.Content | ConvertFrom-Json |
| 103 | Write-Host "Transport: $($json.mcp.transport)" |
| 104 | ``` |