Search code examples
xmlapipowershellservicenow

Pull Specific INC or CR from ServiceNow via Powershell


I am just trying to pull an Incident or a Change Request and its details from ServiceNow based off of its sys_id or number via powershell. I dont even know where to start. Any help would be greatly appreciated!


Solution

  • ServiceNow exposes a standard REST API for every table in the platform. Here are the docs for the ServiceNow Table API. If you want to retrieve a specific Incident record, you would issue a GET request to the following endpoint:

    https://instancename.service-now.com/api/now/table/incident/{incident_sys_id}

    You can use this in combination with PowerShell's Invoke-RestMethod cmdlet to actually pull the details. Example:

    $cred = Get-Credential
    $uri = 'https://instance.service-now.com/api/now/table/incident/{incident_sys_id}'
    Invoke-RestMethod -Uri $uri -Credential $cred
    

    Similar results can be achieved for any table in the system by changing the table portion of the URL.