PowerShell Get All Users script

users
powershell
questions
rest-api

(Dan Hillman) #1

I am trying to use the following PowerShell script to retrieve all of my users, but I keep getting a 404 response. Can anyone help me understand what I am missing?

$apiKey = “***********”
$URI0 = “https://api.pagerduty.com/users
$URI1 = ‘https://api.pagerduty.com/users?limit=100&offset=0
$URI2 = “https://api.pagerduty.com/users?limit=100&offset=100

Invoke-RestMethod -Method Get -Uri $URI0 -Header @{ “Authorization” = $apiKey, “application/vnd.pagerduty+json;version=2”}


(Dan Hillman) #2

Great news... after some further fuddling, I found the issue. The $apikey value needed to be formatted slightly differently in order to be properly recognized:
$apiKey = "Token token=************"


(system) #3