Skip to content

Instantly share code, notes, and snippets.

@brettmillerb
Created February 28, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettmillerb/0826765b89cc46ba88843b7dd033c5d7 to your computer and use it in GitHub Desktop.
Save brettmillerb/0826765b89cc46ba88843b7dd033c5d7 to your computer and use it in GitHub Desktop.
ServiceNow Sys_User
# Eg. User name="admin", Password="admin" for this code sample.
$user = "admin"
$pass = "admin"
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization', ('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept', 'application/json')
$headers.Add('Content-Type', 'application/json')
# Specify endpoint uri
$uri = "https://dev93198.service-now.com/api/now/table/sys_user"
# Specify HTTP method
$method = "post"
$body = @{
name = 'Shawn Melton'
first_name = 'Shawn'
last_name = 'Melton'
email = 'shawn.melton@stuff.com'
}
$body = ConvertTo-Json -InputObject $body
# Send HTTP request
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -Body $body
# Print response
$response.RawContent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment