0

Apologies for having to ask a question like this, self taught powershell user here. Having an issue where I cannot seem to get the value I am after from a JSON return on a GET Invoke-RestMethod.

I am trying to pull JIRA ticket data so I can check to see if a custom field has been updated with a value. I have tried calling the custom field directly in the response however due to way the response is formatted it will only return the column of data and therefore I am unable to use this reponse in my code.

My code is as follows:

$response = Invoke-RestMethod "https://jira-ceg.atlassian.net/rest/servicedeskapi/request/$JIRATICKET" -Method 'GET' -Headers $headers 

$tester = $response.requestFieldValues


$tester

The response I get from JIRA is the following:

    fieldId           label              value                                                                                                                                                   
-------           -----              -----                                                                                                                                                   
summary           Summary            STAFF-NEW - XXXX- NAME 
customfield_10108 iTrent Information Employee ID: XXXX...                                                                                                                              
customfield_10086 Checklist Text     --- ERROR - No Role Entitlement Found - Contact Service Admin                                                                                           
description       Description        A new employee has joined. Please process with the data above.                                                                                          
customfield_10191 New AD Address     XXXX@XXXXX.com                                                                                                                
                                                                                                                                                

I want to capture the value of the field customfield_10191, the field could sometimes be blank too, which I will test later in the script. Any idea how I could do this?

Thanks in advance!

1 Answers1

1

If $tester is an object with properties fieldId,label, and value, you can use a combination of member access (syntax object.property) and Where-Object:

($tester | Where fieldId -eq 'customfield_10191').value

Select-Object also works:

$tester | Where fieldId -eq 'customfield_10191' | Select-Object -Expand value

To return the object that contains the particular customer:

$tester | Where fieldId -eq 'customfield_10191'
AdminOfThings
  • 23,946
  • 4
  • 17
  • 27
  • Thank you! I managed to get this working now using the select-object method. I had issues with the header still coming through into the variable but found another article on here that mentioned -ft removeheader which solved my issue fully. Thank you the script is now working perfectly! – Andy Finch Aug 15 '20 at 12:19