- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-11-2020 08:17 AM
Reference : http://www.john-james-andersen.com/blog/service-now/powershell-probe-and-utility-for-servicenow.html
https://arindamhazra.com/service-now-incident-management-using-powershell/
Sample script to print raw output
# Eg. User name="admin", Password="admin" for this code sample.
$user = "userName"
$pass = "Password"
# 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')
# Specify endpoint uri
$uri = "https://<ENV>.service-now.com/api/now/table/incident?sysparm_limit=1"
# Specify HTTP method
$method = "get"
# Send HTTP request
#$response = Invoke-RestMethod -Headers $headers -Method $method -Uri $uri
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri
# Print response
Write-Output $response.RawContent
#In order to export the content to csv
# Print response
Write-Output $response.RawContent
$responseJSON = $response | ConvertFrom-Json
Write-Output $responseJSON.result
$responseJSON.result | ConvertTo-Csv -NoTypeInformation | Out-File -FilePath D:\AccessDB\test.csv
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Tried it - getting
"Invoke-WebRequest : The remote server returned an error: (401) Unauthorized."
But user and pass is definitely correct (its used somewhere else connecting to API)
Any suggestions?