Ready to get started?

Learn more about the ServiceNow PowerShell Cmdlets or download a free trial:

Download Now

Pipe ServiceNow Data to CSV in PowerShell

Use standard PowerShell cmdlets to access ServiceNow tables.

The CData Cmdlets Module for ServiceNow is a standard PowerShell module offering straightforward integration with ServiceNow. Below, you will find examples of using our ServiceNow Cmdlets with native PowerShell cmdlets.

Creating a Connection to Your ServiceNow Data

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.

$conn = Connect-ServiceNow  -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -Username "$Username" -Password "$Password" -Instance "$Instance"

Selecting Data

Follow the steps below to retrieve data from the incident table and pipe the result into to a CSV file:

Select-ServiceNow -Connection $conn -Table incident | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myincidentData.csv -NoTypeInformation

You will notice that we piped the results from Select-ServiceNow into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.