Skip to main content

42 posts tagged with "PowerShell"

PowerShell Scripting and Automation

View All Tags

How to Generate a Secret Key for HS256 JWTs in the Terminal

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A JSON Web Token signed with HS256 is only as safe as its secret key. Whoever has the key can make tokens your app will accept. A short or guessable key can be found by testing guesses against any token signed with it, with no need to contact your server. One command gives you a key that's long and random enough.

How to Create an HMAC-SHA256 Signature in the Terminal

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

An HMAC is a signature made with a secret key. Anyone with the same key can make the same signature, and anyone without it can't. HMAC-SHA256 signs JSON Web Tokens that use HS256, and many webhooks use it to prove where a request came from. This guide creates one in the terminal and checks it against the official test value.

How to Send a POST Request to a Web API with curl and PowerShell

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

A POST request sends data to a web API: a new order, a message, a reminder. You don't need a separate tool to send one while you build or test an API. curl does it on macOS and Linux, and PowerShell has Invoke-RestMethod built in. This guide sends the same JSON request both ways, reads the status code, and shows the one header you can't leave out.

Fixed: "Response status code does not indicate success: 415 (Unsupported Media Type)" from Invoke-WebRequest

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

The same request worked from curl and failed from PowerShell: Invoke-WebRequest: Response status code does not indicate success: 415 (Unsupported Media Type). When a POST has no -ContentType, PowerShell labels it as form data, and my Microsoft 365 Agents SDK agent's endpoint only accepts JSON. Adding -ContentType "application/json" fixes it.

How to Look Up Azure OpenAI Model Prices with the Azure Retail Prices API

· 12 min read
Jagdish Kumawat
Founder @ Dewiride

A cost estimate is only as good as the price in it, and model prices change. Microsoft publishes every Azure price, including what each Azure OpenAI model costs per million tokens, through the Azure Retail Prices API: a public web address that needs no Azure account. This guide finds one model's prices, decodes the meter names, narrows the list to one deployment type and converts it to another currency, with curl and jq or with PowerShell.

How to Test a Race Condition in a Web API from the Terminal

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A race condition doesn't show up when you send one request at a time. You need several at the same moment, and you don't need a load-testing tool: curl with xargs does it on macOS and Linux, and ForEach-Object -Parallel does it in PowerShell. Then check what's in the database, because the status codes alone can look fine.