Pcornel
Automation · PowerShell Automation

REST APIs

Cheat sheet · https://pcornel.dk/topic.php?topic=5250

Back to the Topic

Answer

PowerShell calls REST APIs with Invoke-RestMethod, which converts JSON responses to objects, supports headers, bodies, authentication and, in PowerShell 7, retries with -MaximumRetryCount.

Remember

  • Invoke-RestMethod parses JSON responses into objects.
  • Pass headers and body explicitly.
  • PowerShell 7 supports retries.

First checks

  • Invoke-RestMethod -Uri <api> -Headers @{Authorization="Bearer $t"} -TimeoutSec 30 — REST call
  • -StatusCodeVariable / try catch for errors — handling
  • Pagination loops — completeness

Verify in this order

request → API → JSON → objects

Where it usually breaks

Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.

REST APIs · PowerShell operational reference

BoundaryREST APIs reference
Runtime identityPowerShell edition/version + command/module source
Persistent intentScript/module/config prerequisites under source control
VerificationRead-only discovery → execution evidence → independent target read-back
Output contractStructured objects/streams before formatting
Failure boundarySeparate engine/binding from transport/API/native and target-state failures

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5250

Confirmation

Confirm action

Continue?