Ready to get started?

Download a free trial of the Jira Service Desk Data Provider to get started:

 Download Now

Learn more:

Jira Service Desk Icon Jira Service Desk ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Jira Service Desk.

Automate Jira Service Desk Integration Tasks from PowerShell



Are you in search of a quick and easy way to access Jira Service Desk data from PowerShell? This article demonstrates how to utilize the Jira Service Desk Cmdlets and the CData ADO.NET Provider for Jira Service Desk for tasks like connecting to Jira Service Desk data, automating operations, downloading data, and more.

The CData Cmdlets for Jira Service Desk are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Jira Service Desk.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to Jira Service Desk, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Jira Service Desk data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Jira Service Desk. To access Jira Service Desk data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Jira Service Desk.

Once you have acquired the necessary connection properties, accessing Jira Service Desk data in PowerShell can be enabled in three steps.

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.

PowerShell

  1. Install the module:

    Install-Module JiraServiceDeskCmdlets
  2. Connect:

    $jiraservicedesk = Connect-JiraServiceDesk -ApiKey "$ApiKey" -User "$User"
  3. Search for and retrieve data:

    $currentstatus = "Open" $requests = Select-JiraServiceDesk -Connection $jiraservicedesk -Table "Requests" -Where "CurrentStatus = `'$CurrentStatus`'" $requests

    You can also use the Invoke-JiraServiceDesk cmdlet to execute SQL commands:

    $requests = Invoke-JiraServiceDesk -Connection $jiraservicedesk -Query 'SELECT * FROM Requests WHERE CurrentStatus = @CurrentStatus' -Params @{'@CurrentStatus'='Open'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Jira Service Desk\lib\System.Data.CData.JiraServiceDesk.dll")
  2. Connect to Jira Service Desk:

    $conn= New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskConnection("ApiKey=myApiKey;User=MyUser;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the JiraServiceDeskDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT RequestId, ReporterName from Requests" $da= New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.requestid $_.reportername }

Update Jira Service Desk Data

PowerShell

Update-JiraServiceDesk -Connection $JiraServiceDesk -Columns @('RequestId','ReporterName') -Values @('MyRequestId', 'MyReporterName') -Table Requests -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskCommand("UPDATE Requests SET CurrentStatus='Open' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert Jira Service Desk Data

PowerShell

Add-JiraServiceDesk -Connection $JiraServiceDesk -Table Requests -Columns @("RequestId", "ReporterName") -Values @("MyRequestId", "MyReporterName")

ADO.NET

$cmd = New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskCommand("INSERT INTO Requests (CurrentStatus) VALUES (@myCurrentStatus)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskParameter("@myCurrentStatus","Open"))) $cmd.ExecuteNonQuery()

Delete Jira Service Desk Data

PowerShell

Remove-JiraServiceDesk -Connection $JiraServiceDesk -Table "Requests" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskCommand("DELETE FROM Requests WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.JiraServiceDesk.JiraServiceDeskParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()