Here you go:
I tested logging an incident in service now, you can modify it to fetch details of any incident:
# Set the credentials
$User = ''
$Pass = ''
# Set headers
$GlobalHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$GlobalHeaders.Add('Accept', 'application/json')
$GlobalHeaders.Add('Content-Type', 'application/json')
# Build & set authentication header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User, $Pass)))
$GlobalHeaders.Add('Authorization', ('Basic {0}' -f $base64AuthInfo))
# Load variable with ServiceNow instance URL
$ServiceNowInstance = 'service now instance url'
# Load a variable with the incident table API endpoint
$CreateIncidentURL = "$ServiceNowInstance/api/now/table/incident"
# Service Desk assignment group sys_id
$AssignmentGroup = ''
Function Add-Ticket {
# Load a variable with data for the description field
$MessageBody = "This is a test incident to test call-out."
# Load a variable with data for the short description field
$ShortDescription = ""
$incidentBody = @{
"short_description"= $ShortDescription;
"urgency"= "2";
"impact"= "2";
"business_service" = "";
"assignment_group" = "";
"cmdb_ci" = "";
"description" = $MessageBody;
"caller_id" = "userid";
"contact_type" = "auto";
}
# Body used to pass the fields I will pupulate within the ticket - there are several, see the docs
$Params = @{
Headers = $GlobalHeaders
Method = "POST"
Uri = $CreateIncidentURL
Body = ($incidentBody | ConvertTo-Json)
}
Try {
Invoke-WebRequest @ParamS -UseBasicParsing -ErrorAction Stop
}
Catch {
# Handle any errors
}
}
# Run the function, Add-Ticket
Add-Ticket