Skip to content

Instantly share code, notes, and snippets.

@akrnmd
Last active June 30, 2021 10:43
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 akrnmd/f9459dababf0803725bbf690c34b6dd6 to your computer and use it in GitHub Desktop.
Save akrnmd/f9459dababf0803725bbf690c34b6dd6 to your computer and use it in GitHub Desktop.
# Parameters
# Example
# $user = "admin"
# $pass = "admin"
# $instansname = "dev00000"
# $targettablename = "incident"
# $baselocalpath = "C:\snowapi\"
# $outfilename = "incident.xls"
$user = "admin"
$pass = "admin"
$instansname = "dev0000"
$targettablename = "table_name"
$baselocalpath = "C:\"
$outfilename = "table_name.xls"
# 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')
# Set fullpath of outfile
$fullpathofoutfile = $baselocalpath + $outfilename
# Specify endpoint uri
# If you need export with filtered data, use next example.
# $uri = "https://" + $instansname + ".service-now.com/incident_list.do?XLS&sysparm_query=priority=1&sysparm_default_export_fields=all"
$uri = "https://" + $instansname + ".service-now.com/" + $targettablename + "_list.do?XLS&sysparm_default_export_fields=all"
# Specify HTTP method
$method = "GET"
# Send HTTP request
Invoke-RestMethod -Headers $headers -Method $method -Uri $uri -OutFile $fullpathofoutfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment