function Get-JiraTeams { <# .SYNOPSIS Get all the team members for each team per what is listed in Jira (tempo) #> [CmdletBinding()] param ( [switch]$RefreshCache ) $logLead = (Get-LogLeadName) $cacheFilePath = (Get-CachePathJiraTeams) if ($RefreshCache) { $cacheFilePath = (Get-CachePathJiraTeams) if (Test-Path -Path $cacheFilePath) { Remove-Item -Path $cacheFilePath -Force } } if (Test-Path -Path $cacheFilePath) { $cachedData = ConvertFrom-Json (Get-Content -Path $cacheFilePath -Raw) return ($cachedData | ConvertTo-JiraTeam) } $logLead = (Get-LogLeadName) $headers = (Get-JiraBearerTokenAuthWebHeader) $headers["Content-Type"] = "application/json" $headers["Accept"] = "application/json" # This gives all the teams available to be picked from # The / 2 / is "I can browse teams to select them" # If it were / 1 / it would be "I am a tempo-teams administrator" $teamsUrl = (Join-UrlComponents -BaseUrl $url -Path "/rest/tempo-teams/2/team" -Query @{ expand = "projects" }) # $t.Where({!$_.name.StartsWith('zz')-and $_.program-eq 'Development'}) | % { "'$($_.Name)' { $($_.id) }" } | Set-Clipboard $arguments = @{ Headers = $headers Uri = $teamsUrl Method = 'GET' } try { $allTeams = Invoke-RestMethod @arguments } catch { Write-Host (Get-LastWebRequestErrorText) Write-ErrorObject -ErrorItem $PSItem return } $teams = @() foreach ($team in $allTeams) { $teamName = $team.name if ($teamName.StartsWith("zz")) { Write-Host "$logLead : Skipping team [$teamName] as it is a 'zz' team" continue } $department = $team.program if ($department -eq "Archived") { Write-Host "$logLead : Skipping team [$teamName] as it is archived" continue } $teamMission = $team.mission $lead = $team.lead $summary = $team.summary $links = @() $teamlinksUrl = (Join-UrlComponents -BaseUrl $url -Path "/rest/tempo-teams/2/team/$($team.id)/link" -Query @{ expand = "projects" }) $arguments = @{ Headers = $headers Uri = $teamlinksUrl Method = 'GET' } try { $teamLinks = Invoke-RestMethod @arguments } catch { Write-Host (Get-LastWebRequestErrorText) Write-ErrorObject -ErrorItem $PSItem return } foreach ($link in $teamLinks.Where({$_.scopeType -eq 'board'})) { $links += @{ TeamName = $link.teamName Board = $link.scope } } $teamMembersUrl = (Join-UrlComponents -BaseUrl $url -Path "/rest/tempo-teams/2/team/$($team.id)/member" -Query @{ expand = "projects" }) $arguments = @{ Headers = $headers Uri = $teamMembersUrl Method = 'GET' } try { $teamMembers = Invoke-RestMethod @arguments } catch { Write-Host (Get-LastWebRequestErrorText) Write-ErrorObject -ErrorItem $PSItem return } $members = @() foreach($member in $teamMembers) { if ($member.member.key -eq $lead) { $lead = $member.member.name } $members += @{ Name = $member.member.name Role = $member.membership.role.name DisplayName = $member.member.displayname Inactive = !$member.member.activeInJira } } $teams += @{ Name = $teamName Summary = $summary Department = $department Mission = $teamMission Lead = $lead AllMembers = $members Members = $members Manager = @{} ScrumMaster = @{} ProductOwner = @{} ProjectManager = @{} Links = $links # RawMembers = $teamMembers } } $allScrumMasters = $teams.AllMembers.Where({$_.Role -eq "Scrum Masters"}) foreach ($team in $teams) { $team.Manager = $team.AllMembers.Where({$_.Role -eq "Manager" -and $_.Name -notin $allScrumMasters.Name}) $team.ProjectManager = $team.AllMembers.Where({$_.Role -eq "Project Manager" -and $_.Name -notin $allScrumMasters.Name}) $team.ProductOwner = $team.AllMembers.Where({$_.Role -eq "Product Owner" -and $_.Name -notin $allScrumMasters.Name}) $team.ScrumMaster = $team.AllMembers.Where({($_.Role -eq "Manager" -or $_.Role -eq "Scrum Masters") -and $_.Name -in $allScrumMasters.Name}) $team.Members = $team.AllMembers.Where({$_.Name -ne $team.Manager.Name -and $_.Name -ne $team.ScrumMaster}) } ConvertTo-Json $teams -Depth 10 | Set-Content -Path $cacheFilePath return ($teams | ConvertTo-JiraTeam) }