Get-MgUserCalendarView : Access is denied. #2908
Unanswered
R00tRx (itwguthub)
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Im trying to create a Daily update for all staff on their calendar entries which then will get sent to all management members.
In theory the script should loop through each user, view their daily entries and then open outlook and send me the updates.
But I keep getting these errors..
Get-MgUserCalendarView : Access is denied. Check credentials and try again.
I tried changing to "Users.ReadAll" , and pretty much all the rest as well
Connect-MgGraph -Scopes "Calendars.Read"
$timeZone = [System.TimeZoneInfo]::FindSystemTimeZoneById("New Zealand Standard Time")
$startDate = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId((Get-Date), $timeZone.Id).Date
$endDate = $startDate.AddDays(1)
$users = Get-MgUser -Filter "accountEnabled eq true" -All
$emailBody = ""
foreach ($user in $users) {
$userId = $user.Id
$calendarEntries = Get-MgUserCalendarView -UserId $userId -StartDateTime $startDate -EndDateTime $endDate
}
if ($emailBody) {
Write-Output "Email body constructed successfully"
Write-Output $emailBody
} else {
Write-Output "No calendar entries found for any user"
}
Disconnect-MgGraph
All reactions