I've been using this command in my script
$jira = Get-JiraIssue -Query $jiraQuery -Credential $jiraCred | Select-Object Assignee,customfield
Which results in an array as such:
Assignee customfield
---- ----
Unassigned D00525FFKSAN0
first.last 1FLSALF05
However, if I run the same command in Start-Job scriptblock:
Start-Job -Name Jira -ScriptBlock {param($jiraQuery,$jiraCred) Get-JiraIssue -Query $jiraQuery -Credential $jiraCred | Select-Object Assignee,customfield} -ArgumentList $jiraQuery, $jiraCred
Receive-Job -Name JIra -Keep
The results end up being like:
Assignee : Unassigned
customfield : ASLFDSGLDMF06
RunspaceId : a670925b-537a-4d54-adce-89c693f3fa9d
--------
Assignee : @{TimeZone=America/Los_Angeles; Key=JIRAUSER0000; AvatarUrl=; Groups=; Active=True; AccountId=; DisplayName=First Last; [email protected]; Locale=; RestUrl=https://jira.com/rest/api/2/user?username=first.last; Name=first.last}
customfield : ASLFDSGLDMF05
RunspaceId : a670925b-537a-4d54-adce-89c693f3fa10d
I've tried using -ExpandProperty on the job results, but then the Assignee property takes over and results in:
Name DisplayName Active
---- ----------- ------
first.last First Last Yes
first.last2 First Last 2 Yes
first.last3 First Last 3 Yes
What's happening here? I can't seem to figure out how to get the same results I'm getting by running the command directly, outside of Start-Job
CodePudding user response:
I bet your request is authenticated inside the script differently than in a dedicated script block. Are you passing credentials elsewhere in the original script?
CodePudding user response:
Your Get-JiraIssue
has a custom formatting view which is lost during serialization as Daniel states in his on point comment.
To get around this, and assuming you're looking for the .Name
property of the nested object in the Assignee
property here is how you can recreate the object:
$job = Start-Job -Name Jira -ScriptBlock {
param($jiraQuery, $jiraCred)
Get-JiraIssue -Query $jiraQuery -Credential $jiraCred
} -ArgumentList $jiraQuery, $jiraCred
Receive-Job $job -Keep | ForEach-Object {
[pscustomobject]@{
Assignee = ($_.Assignee, $_.Assignee.Name)[[bool] $_.Assignee.Name]
customfield = $_.customfield
}
}