Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Automate ServiceNow Integration Tasks from PowerShell
Are you in search of a quick and easy way to access ServiceNow data from PowerShell? This article demonstrates how to utilize the ServiceNow Cmdlets for tasks like connecting to ServiceNow data, automating operations, downloading data, and more.
The CData Cmdlets for ServiceNow are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to ServiceNow.
About ServiceNow Data Integration
CData simplifies access and integration of live ServiceNow data. Our customers leverage CData connectivity to:
- Get optimized performance since CData uses the REST API for data and the SOAP API for schema.
- Read, write, update, and delete ServiceNow objects like Schedules, Timelines, Questions, Syslogs and more.
- Use SQL stored procedures for actions like adding items to a cart, submitting orders, and downloading attachments.
- Securely authenticate with ServiceNow, including basic (username and password), OKTA, ADFS, OneLogin, and PingFederate authentication schemes.
Many users access live ServiceNow data from preferred analytics tools like Tableau, Power BI, and Excel, and use CData solutions to integrate ServiceNow data with their database or data warehouse.
Getting Started
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to ServiceNow, but also an SQL interface; this tutorial shows how to use both to retrieve ServiceNow data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for ServiceNow. To access ServiceNow data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for ServiceNow.
Once you have acquired the necessary connection properties, accessing ServiceNow data in PowerShell can be enabled in three steps.
ServiceNow uses the OAuth 2.0 authentication standard. To authenticate using OAuth, you will need to register an OAuth app with ServiceNow to obtain the OAuthClientId and OAuthClientSecret connection properties. In addition to the OAuth values, you will need to specify the Instance, Username, and Password connection properties.
See the "Getting Started" chapter in the help documentation for a guide on connecting to ServiceNow.
PowerShell
-
Install the module:
Install-Module ServiceNowCmdlets
-
Connect:
$servicenow = Connect-ServiceNow -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -Username "$Username" -Password "$Password" -Instance "$Instance"
-
Search for and retrieve data:
$category = "request" $incident = Select-ServiceNow -Connection $servicenow -Table "incident" -Where "category = `'$category`'" $incident
You can also use the Invoke-ServiceNow cmdlet to execute SQL commands:
$incident = Invoke-ServiceNow -Connection $servicenow -Query 'SELECT * FROM incident WHERE category = @category' -Params @{'@category'='request'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for ServiceNow\lib\System.Data.CData.ServiceNow.dll")
-
Connect to ServiceNow:
$conn= New-Object System.Data.CData.ServiceNow.ServiceNowConnection("OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;Username=MyUsername;Password=MyPassword;Instance=MyInstance;InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the ServiceNowDataAdapter, execute an SQL query, and output the results:
$sql="SELECT sys_id, priority from incident" $da= New-Object System.Data.CData.ServiceNow.ServiceNowDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.sys_id $_.priority }