This PowerShell module provides a series of cmdlets for interacting with the ServiceNow REST API.
IMPORTANT: Neither this module nor its creator are in any way affiliated with ServiceNow.
Requires PowerShell 5.1 or above.
Requires authorization in your ServiceNow tenant. Due to the custom nature of ServiceNow your organization may have REST access restricted. The following are some tips to ask for if you're having to go to your admin for access:
- Out of the box tables should be accessible by granting the
ITILrole. - Custom tables may require adjustments to the ACL.
- The
Web_Service_Adminrole may also be an option.
The ServiceNow module should be installed from the PowerShell Gallery with install-module ServiceNow.
Creating a new session will create a script scoped variable $ServiceNowSession which will be used by default in other functions.
Basic authentication with just a credential...
$params = @{
Url = 'instance.service-now.com'
Credential = $userCred
}
New-ServiceNowSession @paramsOauth authentication with user credential as well as application/client credential. The application/client credential can be found in the System OAuth->Application Registry section of ServiceNow.
$params = @{
Url = 'instance.service-now.com'
Credential = $userCred
ClientCredential = $clientCred
}
New-ServiceNowSession @paramsNote: ServiceNow's API does not support SSO
All examples below assume a new session has already been created.
$filter = @('opened_at', '-ge', (Get-Date).AddDays(-30))
Get-ServiceNowRecord -Table incident -Filter $filterGet-ServiceNowRecord -Table incident -Filter @('short_description','-like','PowerShell')Get-ServiceNowRecord -First 1 -Filter @('short_description','-eq','PowerShell') | Update-ServiceNowIncident -Values @{comments='Updated via PowerShell'}$IncidentParams = @{Caller = "UserName"
ShortDescription = "New PS Incident"
Description = "This incident was created from Powershell"
CustomFields = @{u_service = "MyService"
u_incident_type = "Request"}
}
New-ServiceNowIncident @ParamsThe module can use the Connection parameter in conjunction with the included ServiceNow-Automation.json file for use as an Azure automation integration module. Details of the process is available at Authoring Integration Modules for Azure Automation.
The Connection parameter accepts a hashtable object that requires a username, password, and ServiceNowURL.
Contributions are gratefully received, so please feel free to submit a pull request with additional features or amendments.