Public/Get-O365CalEntry.ps1

Function Get-O365CalEntry{
    param (
        
        # Parameter help description
        [Parameter()]
        [DateTime]
        $StartTime =  (Get-Date -Day 1),
        # Parameter help description
        [Parameter()]
        [DateTime]
        $EndTime = (Get-Date -Day 1).AddMonths(1).AddDays(-1),
        # Parameter help description
        [Parameter()]
        [String]
        $SubjectSearchString = "DTX:"
    )
    $StartTimeStr = $StartTime | Get-Date -f "yyyy-MM-ddT00:00:00"
    $EndTimeStr = $EndTime | Get-Date -f "yyyy-MM-ddT23:59:59"
    $Token = (Get-O365Jwt).Trim()
    $Splat = @{
        Headers = @{
            Authorization = "Bearer $Token"
        }
        Uri = "https://graph.microsoft.com/v1.0/me/events?`$filter=startswith(subject,'$SubjectSearchString') and start/dateTime ge '$StartTimeStr' and end/dateTime le '$EndTimeStr'"
    }
    Write-Verbose "DateRange From: $StartTimeStr"
    Write-Verbose "DateRange To: $EndTimeStr "
    Write-Debug "URI:$($Splat.Uri)"
    Write-Verbose "Token: $($Token.Substring(0,64))..."
    Write-Verbose "Account: $((Get-O365JwtPayload -JwtToken $Token).unique_name)"
    $Results = Invoke-RestMethod @Splat | Select-Object -ExpandProperty value
    $DateTimeUKParse = "MM/dd/yyyy HH:mm:ss"
    $Entries = @()
    $Results | ForEach-Object {
        $x = @{}
            
        $x.ProjectCode = $PSItem.subject.split(":")[1].Trim()

        
        if($PSItem.isAllDay -eq $true){
            $Time = New-TimeSpan -Hours 7 -Minutes 30
        }else{ 
            if($PSVersionTable.PSVersion -lt [Version]::new("6.0")){ # Implies WindowsPowerShell
                $StartTime = [DateTime]$PSItem.start.datetime
                $EndTime = [DateTime]$PSItem.end.datetime
            }else{
                $StartTime = $PSItem.start.datetime
                $EndTime = $PSItem.end.datetime
            }
            
            $start = Get-Date -Year $StartTime.Year -Month $StartTime.Month -Day $StartTime.Day -Hour $StartTime.Hour -Minute $StartTime.Minute -Second 0
            
            $end = Get-Date -Year $EndTime.Year -Month $EndTime.Month -Day $EndTime.Day -Hour $EndTime.Hour -Minute $EndTime.Minute -Second 0
            
            $Time = New-TimeSpan -Start $start -End $end

                # $Time = New-TimeSpan -Start ([datetime]::ParseExact($PSItem.start.datetime,$DateTimeUKParse,[Globalization.CultureInfo]::CreateSpecificCulture('en-GB'))) -End ([datetime]::ParseExact($PSItem.end.datetime,$DateTimeUKParse,[Globalization.CultureInfo]::CreateSpecificCulture('en-GB')))
        }

        $x.AllocatedTime = "$($Time.Hours).$([math]::Round($Time.Minutes/60 * 10))" #TODO: Needs fine tuning.
        
        $x.Month = (Get-Culture).DateTimeFormat.GetMonthName($StartTime.Month).toLower()
        $x.Day = $StartTime.Day

        $Entries += [PSCustomObject]$x
    }
    $Entries
}