To send a text from PowerShell, call Invoke-RestMethod with a POST to your SMS provider's endpoint, pass the API key in a header, and send the body as JSON built from a hashtable. It works in Windows PowerShell 5.1 and PowerShell 7, and there's no module to install.

We make Ready, so the example uses the Ready REST API and only the request shape we document. The goal is a small reusable function you can drop into a scheduled task, a monitoring script or an onboarding automation.

What you need first

  1. An API key, sent in an X-API-Key header.
  2. A card and a number on the account. The number is $2 a month. To build and test first, create a test key (Settings, Developers, Environment: Test): it simulates every send, with no card, number or charge. Add the card and number before you go live.
  3. Recipients who agreed to texts. Each request carries consent_attested = $true, which is your statement that the person opted in. Texting your own staff for alerts is fine when they've agreed to it; texting customers needs their consent.
  4. A registration plan. An account can send up to 500 texts a month before it registers for 10DLC; most approvals take 2 to 7 days.

Store the key safely

Don't paste the key into the script. Two reasonable options on Windows:

  • An environment variable set at the machine or service level, read with $env:READY_API_KEY.
  • The SecretManagement module with a vault, read with Get-Secret.

Never write the key to a transcript. If you use Start-Transcript, make sure the header isn't echoed. Our key security post covers rotation.

The function

function Send-ReadySms {
    param(
        [Parameter(Mandatory)][string]$To,
        [Parameter(Mandatory)][string]$Body,
        [string]$IdempotencyKey = [guid]::NewGuid().ToString()
    )

    $headers = @{
        "X-API-Key"       = $env:READY_API_KEY
        "Idempotency-Key" = $IdempotencyKey
    }
    $payload = @{
        to               = $To
        body             = $Body
        consent_attested = $true
    } | ConvertTo-Json

    try {
        Invoke-RestMethod -Method Post `
            -Uri "https://api.tryready.com/v1/messages" `
            -Headers $headers `
            -ContentType "application/json" `
            -Body $payload `
            -TimeoutSec 20
    }
    catch {
        $status = $_.Exception.Response.StatusCode.value__
        Write-Error "SMS failed with HTTP $status"
        throw
    }
}

Send-ReadySms -To "+12125550199" -Body "Backup job finished on SRV-01."

ConvertTo-Json handles quoting, so a message with quotes or a newline doesn't break the payload. The -TimeoutSec stops a hung connection from freezing a scheduled task. The response fields are listed in the messages API reference.

Retry without double-texting

For a flaky network, wrap the call in a loop and reuse the same idempotency key on each attempt. The key is why a retry is safe: the API treats a repeated key as the same send.

$key = [guid]::NewGuid().ToString()
$sent = $false
foreach ($i in 1..3) {
    try {
        Send-ReadySms -To "+12125550199" -Body "Disk space low on SRV-01." -IdempotencyKey $key
        $sent = $true
        break
    }
    catch {
        $code = $_.Exception.Response.StatusCode.value__
        if ($code -ge 400 -and $code -lt 500 -and $code -ne 429) { throw }
        Start-Sleep -Seconds ([math]::Pow(2, $i))
    }
}
if (-not $sent) { Write-Error 'SMS alert not sent after 3 attempts'; exit 1 }

Retry on timeouts and 429 responses with the same key. A 503 was not sent, but the same key replays that stored error, so resend it under a new key; after a 504, or a code ending in OUTCOME_UNKNOWN, check GET /v1/messages first. A 4xx like a refused number won't improve on retry. More on this is in the retries guide.

Good uses and bad uses

PowerShell texting is good for operational alerts to a handful of people: failed backups, expiring certificates, a service that stopped. It's a poor fit for marketing blasts to a list, where you need opt-out handling and registration. If you're building system alerts and notifications, keep the recipient list short and make sure each person can reply STOP.

Cost

Each segment on the Standard rate is $0.0075 plus a $0.0045 carrier fee, excluding optional screening. A 140-character alert is one segment, so 200 alerts a month is 200 × ($0.0075 + $0.0045). See pricing.

Ready's all-in prices per segment include the carrier fee but not screening: Scrub lists and Number validation, the two switches in Settings under Compliance, each add $0.003 per segment when switched on, shown as screening on your bill, and both are off by default. Unless you turn the opt-out footer off, the first text to each contact, and one again from time to time, also gets "Reply STOP to opt out" and your business name if the message does not already have them, so a text close to the segment limit can bill one more segment.

FAQ

Does this work in Windows PowerShell 5.1?

Yes. Invoke-RestMethod has been there for years. On older systems you may need to enable TLS 1.2 first with [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12.

How do I send to several numbers?

Loop over them with foreach and a distinct idempotency key per recipient, or use the bulk endpoint, which takes an array of up to 100 numbers per call (bulk docs).

Can I run this from Task Scheduler?

Yes. Run it under a service account, set the key as a machine-level environment variable that account can read, and log failures to a file or the event log so a silent failure doesn't go unnoticed.

The short version

One function, a JSON body from a hashtable, a timeout and a stable idempotency key. If you'd rather test from a shell first, the curl guide shows the raw request.