I finally am getting around to posing the addition to my previous blog post for Creating and updating Service Now Incidents.
Same as before you need to know your Sys_ID’s of the objects you are going to use. Like your user account, The assignment group and anyone else you are going to need to add to this change request.
Finding Sys_IDs is easy once you figure out they are a 32 character code listed in the URL of the objects you are looking for. Same with your Incident’s.
First Open an existing incident with your name in it. On the right of your name is the “i” Click on it and then the “Open Record” button on the upper right-hand side. ![]()
This will open your User record in ServiceNow. In the URL you will see your Sys_ID. ![]()
You can do this for the rest of the other Sys_ID’s you need. Also in this change, I have the parent filed in the script, So if you find the Sys_ID of the parent Incident you can put that as the parent for the change.
From there you just need to gather all the info that is required or you would like to use.
# Create New ServiceNow Change
# Chris Hildebrandt
# 10-26-2018
# Ver 1.0
# Script will create a new ServiceNow Change via Powershell
#______________________________________________________________________________________
# Eg. User name="admin", Password="admin" for this code sample.
$SNuser = "admin" #enter your ServiceNow Username
$SNpass = "admin" #enter your ServiceNow Password
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $SNuser, $SNpass)))
# 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
$CHGuri = "https://YOURSERVICENOW.service-now.com/api/now/table/change_request"
# Specify HTTP method
$Postmethod = "post"
# Specify request body
$CHGbody = @{ #Create Body of the Post Request
requested_by = "Requested By Sys_ID"
category = "Other"
service_offering = "Other"
reason = "software upgrade"
u_client_impact = "No"
start_date = "2018-11-1 01:00:00"
end_date = "2018-11-30 23:00:00"
watch_list = "Watch List Sys_ID"
parent = "Parent Incident or Change Request"
urgency = "2"
risk = "4"
type = "Standard"
state = "1"
assignment_group = "Assigned To's Group Sys_ID"
assigned_to = "Assigned To Sys_ID"
short_description = "Short Description"
description = "Description: Test"
justification = "Justification Notes"
change_plan = "Change Plan:"
test_plan = "Test Plan: Notes"
backout_plan = "Back Out Plan: Notes"
u_change_summary = "Change Summary: Notes"
}
$CHGbodyjson = $CHGbody | ConvertTo-Json
# POST to API
Try
{
# Send API request
$ChangePOSTResponse = Invoke-RestMethod -Method $Postmethod -Uri $CHGuri -Body $CHGbodyjson -TimeoutSec 100 -Headers $headers -ContentType "application/json"
}
Catch
{
Write-Host $_.Exception.ToString()
$error[0] | Format-List -Force
}
# Pulling ticket ID from response
$ChangeID = $ChangePOSTResponse.result.number
$ChangeSysID = $ChangePOSTResponse.result.sys_id
# Verifying Change created and show ID
IF ($ChangeID -ne $null)
{
"Created Change With ID:$ChangeID"
"Change created With Sys_ID:$ChangeSysID"
}
ELSE
{
"Change Not Created"
}
The script below is an extremely basic script that I have built for my use case but this has huge building blocks from here. In this script, you need to edit the username and password. You can use encrypted if you like. You will need your ServiceNow URL and of course all your Sys_ID’s and info from the fields that have drop-down menus. Later on, in a blog post, I will put something out there on a script I created making all the Service Now code into functions to use in much larger scripts.
This script below will update an existing Service Now Change. You will need the Sys_ID for the Change you are updating. That can be found in the URL of the change.
![]()
# Update New ServiceNow Change
# Chris Hildebrandt
# 10-26-2018
# Ver 1.0
# Script will Update a ServiceNow Change via Powershell
#______________________________________________________________________________________
# Eg. User name="admin", Password="admin" for this code sample.
$SNuser = "admin" #enter your ServiceNow Username
$SNpass = "admin" #enter your ServiceNow Password
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $SNuser, $SNpass)))
# 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
$UpdateCHGuri = "https://YOURSERVICENOW.service-now.com/api/now/table/change_request/THE Change you want to updates Sys_ID"
# Specify HTTP method
$Patchmethod = "patch"
# Specify request body
$UpdateCHGbody = @{ #Create Body of the Post Request
state="8"
comments="Additional Coments "#Add the comments you want to add to the Change.
u_change_summary="Change Summary"#Add to the Change Summary.
}
$UpdateCHGbodyjson = $UpdateCHGbody | ConvertTo-Json
# Send HTTP request
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri -Body $body
# Send API request
$UpdateChangePOSTResponse = Invoke-RestMethod -Method $Patchmethod -Uri $UpdateCHGuri -Body $UpdateCHGbodyjson -TimeoutSec 100 -Headers $headers -ContentType "application/json"
I was working with Comments and Change Summary you can add other fields as you like.
The Links for these Scripts are on my GitHub repo HERE. Along with a few other Scripts.

