PowerShell error handling
Good error handling makes scripts easier to support, safer to run, and simpler to troubleshoot.

Before you begin
- Install the EtherAssist module only on trusted workstations or automation hosts.
- Configure API keys through approved secret handling and never commit them to source control.
- Use read-only examples first, then add write actions only after review.
- Test scripts with sample data before running against production tenants.
Ask for
- Parameter validation.
- Try/catch blocks around external calls.
- Clear user-facing error messages.
- Non-zero exit behaviour for automation.
- Structured logging without secrets.
Prompt pattern
Review this PowerShell script and improve error handling. Keep it read-only, avoid logging secrets, add parameter validation, and return clear messages for missing files, authentication failure, and API throttling.
Tips
- Keep names, prompts, and configuration values specific to the task you are performing.
- Check role, subscription, region, and tenant policy when a feature is not visible.
Troubleshooting
| Issue | What to check |
|---|---|
| Module command is not found | Confirm the module is installed, imported, and available in the current PowerShell session. |
| API request fails | Check API key configuration, network access, and retry settings. |
| Output is hard to audit | Use JSON/object output and avoid logging secrets or raw sensitive content. |