ps/Modules/Cole.PowerShell.Developer/Public/Get-ScrumTeams.ps1
2023-05-30 22:51:22 -07:00

41 lines
1.4 KiB
PowerShell

function Get-ScrumTeams {
<#
.SYNOPSIS
Get the scrum teams per a document in Confluence (see: {function:Get-ScrumTeamsFromConfluence})
.PARAMETER Refresh
Force a refresh of the data.
#>
param (
[Parameter(Mandatory = $false)]
[switch]$Refresh
)
$logLead = (Get-LogLeadName)
# Check to see if the file exists in our normal cache location
# If the file doesn't exist, get the data from confluence, try to cache it, return the data
$cacheFilePath = (Get-CacheFile 'ScrumTeams')
$cachedFileExists = (Test-Path $cacheFilePath)
if (!$Refresh -and $cachedFileExists) {
$cachedData = (Get-Content $cacheFilePath)
return $cachedData | ConvertFrom-Json | ConvertTo-Hashtable | ConvertTo-ScrumTeam
} else {
$scrumTeams = Get-ScrumTeamsFromConfluence
try {
$scrumTeams | ConvertTo-Json -Depth 10 | Set-Content -Path $cacheFilePath -Force
} catch {
$errorObject = $PSItem
if (!(Test-IsUserLocalAdministrator)) {
Write-Host "$logLead : The cached data could not be saved. Is there a permissions concern?"
} else {
Write-Host "$logLead : The cached data could not be saved. Examine the error object for more details."
Write-ErrorObject $errorObject
}
}
return $scrumTeams
}
}