![]() |
VOOZH | about |
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.
CData simplifies access and integration of live ServiceNow data. Our customers leverage CData connectivity to:
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.
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, register an OAuth app with ServiceNow to obtain the OAuthClientId and OAuthClientSecret connection properties. In addition to the OAuth values, specify the Instance, Username, and Password connection properties.
See the "Getting Started" chapter in the help documentation for a guide on connecting to ServiceNow.
Install the module:
Install-Module ServiceNowCmdlets
Connect:
$servicenow = Connect-ServiceNow -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -Username "$Username" -Password "$Password" -URL "$URL" -InitiateOAuth "$InitiateOAuth"
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'}
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;URL=https://myinstance12345.service-now-com;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
}
Download a free trial of the ServiceNow Data Provider to get started:
Download NowLearn more:
👁 ServiceNow IconRapidly create and deploy powerful .NET applications that integrate with ServiceNow data including Schedules, Timelines, Questions, Syslogs, and more!