Regarding the initial question, I've been in contact with Microsoft support, and Microsoft's working on an option to get the currently active timeOff objects in some sort of filter for the API. It's not high priority, but it's atleast on their roadmap.
List timeOff MSShift
danhol13
6
Reputation points
If I run the function below, I'll only get the timeOff objects that start and end between $dateFrom and $dateTo. The problem is that I wont get the current "active" timeOffs, if say a timeOff object lasts the whole week, then it would currently be "active". So I want to be able to get those aswell. Cause now I will only get the timeOff objects that's "active" on that day, and not the ones that starts before and ends after. Is there any way to get those too?
Here's an example where two employees are sick more than one day, which my current API request won't get:
function Get-MgShiftTimeOffList {
param (
#Id of the Team to get shifts from
[Parameter(Mandatory)]$teamId,
#Id of the user that the request is sent on the behalf of
[Parameter(Mandatory)]$actAsUID,
#Timespan to fetch shifts from
[Parameter(Mandatory)][datetime]$dateFrom,
[datetime]$dateTo = $dateFrom.AddDays(1)
)
#Convert to "ISO 8601" date format, which is supported in json queries
$convertedDateFrom = [Xml.XmlConvert]::ToString($dateFrom,[Xml.XmlDateTimeSerializationMode]::Utc)
$convertedDateTo = [Xml.XmlConvert]::ToString($dateTo,[Xml.XmlDateTimeSerializationMode]::Utc)
$splat = @{
"Method" = "GET"
"Uri" = "https://graph.microsoft.com/v1.0/teams/$teamId/schedule/timesOff"
"Headers" = @{
"Authorization" = "Bearer $(Get-MgAccessToken)"
"MS-APP-ACTS-AS" = $actAsUID
}
"Body" = @{
'$filter' = "sharedTimeOff/startDateTime ge $convertedDateFrom and sharedTimeOff/endDateTime le $convertedDateTo"
}
}
Invoke-RestMethod @splat
}
Get-MgShiftTimeOffList -teamId (Redacted) -acAsUID (Redacted) -dateFrom (Get-Date "09/09/22 00:00")