functions/Get-BBTerms.ps1
<#
.Synopsis Gets the terms for the Blackboard Learn Environment. Allows for some reusable filters based upon start and end dates configured in Blackboard. .DESCRIPTION Gets the terms for the Blackboard Learn Environemnt. Allows for some reusable filters based upon start and end dates configured in Blackboard. .EXAMPLE Get-BBTerms -TermID 'externalId:30700' .EXAMPLE Get-BBTerms -TargetTerm 'AllCurrent' #> function Get-BBTerms { [CmdletBinding(SupportsShouldProcess)] [Alias()] Param ( [string]$TermID, [ValidateSet("AllCurrent", "LastToEnd", "NextToStart", "CurrentAndFuture")] [string]$TargetTerm = $null ) Begin { } Process { if (!$TermID -eq ""){ $apiurl = "/learn/api/public/v1/terms/$TermID" }else{ $apiurl = "/learn/api/public/v1/terms" } $Terms = Invoke-BBRestMethod -API $apiurl ` -Method Get ` -ContentType application/json Write-Verbose "$Terms" If ($TargetTerm -eq "AllCurrent"){ $CurrentTerms = $($Terms | where-object {$_.availability.duration.start -lt $(Get-Date) -and $($_.availability.duration.end -gt $(Get-Date))}) return $CurrentTerms }elseif ($TargetTerm -eq "LastToEnd") { #Sort the terms by end date and return the last one to end. $LastTerm = $($Terms | Sort-object -Property {$_.availability.duration.end} | where-object {$_.availability.duration.end -lt $(Get-Date)}) | Select-Object -last 1 return $LastTerm }elseif ($TargetTerm -eq "NextToStart") { $NextTerm = $($Terms | Sort-object -Property {$_.availability.duration.start} | where-object {$_.availability.duration.start -gt $(Get-Date)}) | Select-Object -first 1 return $NextTerm }elseif ($TargetTerm -eq "CurrentAndFuture") { $CurrentAndFutureTerms = $($Terms | Sort-object -Property {$_.availability.duration.end} | where-object {$_.availability.duration.end -gt $(Get-Date)}) return $CurrentAndFutureTerms }else { return $Terms } } End { } } |