Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →How to pipe Jira Service Management Data to CSV in PowerShell
Use standard PowerShell cmdlets to access Jira Service Management tables.
The CData Cmdlets Module for Jira Service Management is a standard PowerShell module offering straightforward integration with Jira Service Management. Below, you will find examples of using our JiraServiceDesk Cmdlets with native PowerShell cmdlets.
Creating a Connection to Your Jira Service Management Data
You can establish a connection to any Jira Service Desk Cloud account or Server instance.
Connecting with a Cloud Account
To connect to a Cloud account, you'll first need to retrieve an APIToken. To generate one, log in to your Atlassian account and navigate to API tokens > Create API token. The generated token will be displayed.
Supply the following to connect to data:
- User: Set this to the username of the authenticating user.
- APIToken: Set this to the API token found previously.
Connecting with a Service Account
To authenticate with a service account, you will need to supply the following connection properties:
- User: Set this to the username of the authenticating user.
- Password: Set this to the password of the authenticating user.
- URL: Set this to the URL associated with your JIRA Service Desk endpoint. For example, https://yoursitename.atlassian.net.
Note: Password has been deprecated for connecting to a Cloud Account and is now used only to connect to a Server Instance.
Accessing Custom Fields
By default, the connector only surfaces system fields. To access the custom fields for Issues, set IncludeCustomFields.
$conn = Connect-JiraServiceDesk -ApiKey "$ApiKey" -User "$User"
Selecting Data
Follow the steps below to retrieve data from the Requests table and pipe the result into to a CSV file:
Select-JiraServiceDesk -Connection $conn -Table Requests | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myRequestsData.csv -NoTypeInformation
You will notice that we piped the results from Select-JiraServiceDesk 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.Deleting Data
The following line deletes any records that match the criteria:
Select-JiraServiceDesk -Connection $conn -Table Requests -Where "CurrentStatus = Open" | Remove-JiraServiceDesk
Inserting and Updating Data
The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Jira Service Management, checking first whether a record already exists and needs to be updated instead of inserted.
Import-Csv -Path C:\MyRequestsUpdates.csv | %{ $record = Select-JiraServiceDesk -Connection $JiraServiceDesk -Table Requests -Where ("Id = `'"+$_.Id+"`'") if($record){ Update-JiraServiceDesk -Connection $jiraservicedesk -Table Requests -Columns ("RequestId","ReporterName") -Values ($_.RequestId, $_.ReporterName) -Where ("Id = `'"+$_.Id+"`'") }else{ Add-JiraServiceDesk -Connection $jiraservicedesk -Table Requests -Columns ("RequestId","ReporterName") -Values ($_.RequestId, $_.ReporterName) } }
As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!