This PowerShell module provides a series of cmdlets for interacting with the ServiceNow REST API, performed by wrapping Invoke-RestMethod
for the API calls.
IMPORTANT: Neither this module nor its creator are in any way affiliated with ServiceNow.
The module has been renamed from PSServiceNow to ServiceNow for version 1. This change moves us away from the reserved "PS" prefix. Since the name change is a major change for the user base and the project was never incremented to v1 we've taken the opportunity to label it such.
In addition to the name change the following high level changes have been made:
Back End:
- The module structure has been updated to individual files for each function.
- The build process has been migrated from MAKE to psake with support of the BuildHelpers module.
- Pester testing has been expanded to cover more scenarios.
- Improved code formatting, removed aliases, fixed file encoding.
The gains are marginal in some aspects, but intended to allow for better management in the future.
Front End:
- The following fields are now returned in the DateTime format instead of string: 'closed_at','expected_start','follow_up','opened_at','sys_created_on','sys_updated_on','work_end','work_start' [v1.0.1 Update: This process now attempts to format the property as DateTime based off your local culture settings, a universal
yyyy-MM-dd HH:mm:ss
format, and finally leaves the property as a string if those two convert attempts fail]. - The formatting of returned data has been updated across all the
Get
functions exceptGet-ServiceNowTable
. This means you'll see a handful of default properties returned and can useFormat-List
orSelect-Object
to view all other properties associated with the object.
These changes should improve your ability to filter on the right, especially by DateTime, as well as return more information in general.
Requires PowerShell 3.0 or above as this is when Invoke-RestMethod
was introduced.
Download the latest release and extract the .psm1 and .psd1 files to your PowerShell profile directory (i.e. the Modules
directory under wherever $profile
points to in your PS console) and run:
Import-Module ServiceNow
Once you've done this, all the cmdlets will be at your disposal, you can see a full list using Get-Command -Module ServiceNow
.
Set-ServiceNowAuth -url InstanceName.service-now.com -Credentials (Get-Credential)
The URL should be the instance name portion of the FQDN for your instance. For if you browse to https://yourinstance.service-now.com
the URL required for the module is yourinstance.service-now.com
.
Import-Module ServiceNow
Set-ServiceNowAuth
Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'}
Import-Module ServiceNow
Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'} -ServiceNowCredential $PSCredential -ServiceNowURL $ServiceNowURL
$Incident = Get-ServiceNowIncident -Limit 1 -MatchContains @{short_description='PowerShell'}
Update-ServiceNowIncident -SysID $Incident.Sys_ID -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 @Params
The 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.
- Get-ServiceNowChangeRequest
- Get-ServiceNowConfigurationIte
- Get-ServiceNowIncident
- Get-ServiceNowRequest
- Get-ServiceNowTable
- Get-ServiceNowTableEntry
- Get-ServiceNowUser
- Get-ServiceNowUserGroup
- New-ServiceNowIncident
- New-ServiceNowQuery
- New-ServiceNowTableEntry
- Remove-ServiceNowAuth
- Remove-ServiceNowTableEntry
- Set-ServiceNowAuth
- Test-ServiceNowAuthIsSet
- Update-ServiceNowChangeRequest
- Update-ServiceNowIncident
- Update-ServiceNowNumber
- Update-ServiceNowTableEntry
This module comes with Pester tests for unit testing.
This module has been created as an abstraction layer to suit my immediate requirements. Contributions are gratefully received however, so please feel free to submit a pull request with additional features or amendments.
Author:: Sam Martin