For automation purposes, I needed a tool to interact with the REST API of Atlassian Jira over Powershell commands.

I found a great module developed by replicaJunction and contributors on Github called PSJira.

Installation

You will need

First-Run

Set-JiraConfigServer -Server 'https://my.jira.server.com:port'

Setup jira credentials in .ps1

Encrypt credentials (Once)

Do this with the Windows session of the user who will launch the .ps1 scripts (service account)

$passwd = ConvertTo-SecureString PlainTextPassword -AsPlainText -Force
$encrypted = ConvertFrom-SecureString -secureString $passwd
$encrypted | Set-Content c:\path\cred.txt

In your .ps1 script

Load credential, and launch a connection to Jira.

$secure = Get-Content 'C:\path\cred.txt' | convertto-securestring
$cred = New-Object System.Management.Automation.PSCredential ("Jira User", $secure)
New-JiraSession -Credential $cred

Basics commands

Get-JiraIssue #-Query -Filter -Key
Add-JiraIssueComment TEXT -VisibleRole 'All Users'
Set-JiraIssue #-Assignee
New-JiraIssue #-Project PROJECT_NAME -IssueType Bug -Priority 1 -Summary 'Test from PSJira' -Description 'Content of your Bug Issue'
``

#### Examples

In my case, we created a bot called [Lucy](http://www.imdb.com/title/tt2872732/) who launch tidies tasks on our Jira instance (scheduled with RES Automation Manager), she can update idle tickets for example, or automatically assign tickets to Administrators based on Jira filters, etc..

I used PowerShell's `Get-Random` function to render her speech more 'Human', she takes a random sentence on a simple txt file.

```powershell
$random = Get-Content 'C:\path\Speak.txt' | Get-Random
Get-JiraIssue -Filter YOU_FILTER_ID | Add-JiraIssueComment $random -VisibleRole 'All Users'

Automation, Automation, Automation.

That’s all folks!

zoph.