web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Sync calenders of user...
Power Automate
Unanswered

Sync calenders of users in AD Group to one Shared Calender

(0) ShareShare
ReportReport
Posted on by 8

Recently we have migrated to a Hybrid office environment. Meaning we have onprem AD and "Cloud" Azure AD and Exchange Online. Because of this some own build automating apps don't work because Exchange Online uses the Graph API and Exchange (2016) onprem doesn't.

 

So we have to convert some apps and for that i want to use Power Automate.

 

Today i'm facing the use case were we have multiple AD users that are assigned to an specific AD group from which we have to sync there personal calender to one "Global ReadOnly" calender. For that i wanted to make a new Shared Mailbox and give everybody read-only access to the shared mailbox calender. In that calender all the appointments of the users in the group has to show up. In this way users have one calender for themselves and one where they can see an total overview of what everybody is doing. 

 

The workflow to have users make an appointment in there personal calendar AND a shared one for everybody to see doesn't fit the current workflow. For example, someone gets invited to a Teams-meeting, clicks on accept and it's in there personal calendar. Now the user also has to think to put it in the shared calendar. This get's forgotten and that's why we wan't to automate it.

 

Looking at the Graph API it is possible. But i wanted to do it in Power Automate if possible, because it's easy and others can also adjust / maintain it if needed.

 

Thanks for the help in advance.

Categories:
I have the same question (0)
  • eliotcole Profile Picture
    4,363 Moderator on at

    I think that this is the kind of thing that needs to be placed into the new user workflow for your AD/Azure AD function, @TripleNico ... however, you'll need to have all current users up to scratch, too.

     

    In terms of the ideal way to do this, I also don't think that messing with their personal calendars is the way, as it could cause some major issues.

     

    Better ensure that every user has the additional calendar inside their own calendar set so that they receive notifications on it. That said, I'm not sure how that's done based on a brief look at the Graph Calendar API section (perhaps it's in Group).

     

    All of this is one of many reasons why it's imperative to have a decent, basic, solid, Azure AD hierarchical groups setup. As when you realise that there's no 'All staff' group, things start going to pot. 😅

     

    Using Flow

    Alternatively, a more onerous solution that I've used recently is to utilise an 'all staff' group, and either by:

    • An Apply to each flow run (with concurrency) on the members of that group ...
      or
    • A batch Graph API call (or two)

    Send any new (or modified) items in a group calendar into individual staff member calendars using the Create event graph call.

     

    I'm pretty sure that I used this in a solution elsewhere, recently, so it's possible I've noted it!

     

    EDIT - Yep ... Here it is:

    Search For Users And HTTP Request The Event Into Their Calendar

    Spoiler (Highlight to read)

    What this does is find all the users in your company (more after the flow on that) then for each of them it sends a request to Microsoft to add the event into their calendar:

     

    solution.jpg

     

    Users

    You can leave the number blank if your firm has under 1000 employees, otherwise it's wise to overshoot the amount of users here by a fair bit. So I did that as an example, just in case, as I have 9.

    Optional Users

    If you really want to future proof it make a userLimitVAR integer variable with an initial setting of 1000, a Do until action (with the Users action inside) that runs until the length() of the Users action is not equal to the userLimitVAR, and at the end of each loop inside that, add 1000 to the userLimitVAR. If you wish to count the users you can also populate a userCountVAR that contains that length(). Then pipe the Users result into a set variable for a usersARR array variable also at the end of the loop. All this does is ensure that you'll always get all the users.

     

    Send an HTTP request (Office 365 Groups)

    This is the meat of what you wanted to do, this HTTP request creates an event for whichever User Id you enter in the URI field, but it needs the JSON data to make it with.

     

    It essentially performs the same action for any user that you would accomplish using the Office 365 Outlook connector's Create Event action. If you wanted to use this method to do that, you would replace the "users/id/" part with "me/" instead.

    URI

    The URI field here is:

     

     

     

     

     

    https://graph.microsoft.com/v1.0/users/%7B@{items('Apply_to_each')?['Id']}%7D/calendar/events

     

     

     

     

     

    The "@{items('Apply_to_each')?['Id']}" bit is representative of the graphical 'User id' that you see in the above image. If you have your Apply to each action named the same, then you might be able to paste that straight into the field without issue, but no guaruntees.

    Body

    The Body field is:

     

     

     

     

     

    {
     "subject": "Eliot's Test Event",
     "body": {
     "contentType": "HTML",
     "content": "Call link: https://aka.ms/mmkv1b Submit a question: https://aka.ms/ybuw2i"
     },
     "start": {
     "dateTime": "2022-05-15T17:00:00",
     "timeZone": "UTC"
     },
     "end": {
     "dateTime": "2022-05-15T17:05:00",
     "timeZone": "UTC"
     },
     "location": {
     "displayName": "Skype for Business"
     }
    }

     

     

     

     

     

    This is taken from the example given on the Graph Explorer page (when you can try things like this out), but there are further examples on the documentation pages, here.

    Extra Data?

    If you have extra information that you wish to include, or retrieve dates/subjects/information from a list or something, just subsume this into your logic.

     

    If you need something more complex, then you'll need to show us your flow as it is. But I reckon you can slide this in where-ever you need it.

    Failures?

    Don't worry about these. Anyone that has a calendar will get the event.

     

    You will almost definitely get failures if you are in a company of more than a few employees. This is because some users in M365 do not have licences for the functions you're accessing here.

     

    A more appropriate way to do this and illicit less errors in the loop would be to use an "All Staff" group to run this on. That way it will add it for all the staff, and they are almost 100% likely to have a full office licence, or at least Outlook. 😉

     

    Or you could list all users, then check their licences, then use the ones with ... (you don't need to, though)

    What this does is find all the users in your company (more after the flow on that) then for each of them it sends a request to Microsoft to add the event into their calendar:     Users You can leave the number blank if your firm has under 1000 employees, otherwise it's wise to overshoot the amount of users here by a fair bit. So I did that as an example, just in case, as I have 9. Optional Users If you really want to future proof it make a userLimitVAR integer variable with an initial setting of 1000, a Do until action (with the Users action inside) that runs until the length() of the Users action is not equal to the userLimitVAR, and at the end of each loop inside that, add 1000 to the userLimitVAR. If you wish to count the users you can also populate a userCountVAR that contains that length(). Then pipe the Users result into a set variable for a usersARR array variable also at the end of the loop. All this does is ensure that you'll always get all the users.   Send an HTTP request (Office 365 Groups) This is the meat of what you wanted to do, this HTTP request creates an event for whichever User Id you enter in the URI field, but it needs the JSON data to make it with.   It essentially performs the same action for any user that you would accomplish using the Office 365 Outlook connector's Create Event action. If you wanted to use this method to do that, you would replace the "users/id/" part with "me/" instead. URI The URI field here is:           https://graph.microsoft.com/v1.0/users/%7B@{items('Apply_to_each')?['Id']}%7D/calendar/events           The "@{items('Apply_to_each')?['Id']}" bit is representative of the graphical 'User id' that you see in the above image. If you have your Apply to each action named the same, then you might be able to paste that straight into the field without issue, but no guaruntees. Body The Body field is:           { "subject": "Eliot's Test Event", "body": { "contentType": "HTML", "content": "Call link: https://aka.ms/mmkv1b Submit a question: https://aka.ms/ybuw2i" }, "start": { "dateTime": "2022-05-15T17:00:00", "timeZone": "UTC" }, "end": { "dateTime": "2022-05-15T17:05:00", "timeZone": "UTC" }, "location": { "displayName": "Skype for Business" } }           This is taken from the example given on the Graph Explorer page (when you can try things like this out), but there are further examples on the documentation pages, here. Extra Data? If you have extra information that you wish to include, or retrieve dates/subjects/information from a list or something, just subsume this into your logic.   If you need something more complex, then you'll need to show us your flow as it is. But I reckon you can slide this in where-ever you need it. Failures? Don't worry about these. Anyone that has a calendar will get the event.   You will almost definitely get failures if you are in a company of more than a few employees. This is because some users in M365 do not have licences for the functions you're accessing here.   A more appropriate way to do this and illicit less errors in the loop would be to use an "All Staff" group to run this on. That way it will add it for all the staff, and they are almost 100% likely to have a full office licence, or at least Outlook.   Or you could list all users, then check their licences, then use the ones with ... (you don't need to, though)
  • TripleNico Profile Picture
    8 on at

    Hi @eliotcole thanks for you detailed reply. I looked into this and it could be a great solution, although it isn't exactly what i was looking for i can rebuild it to my purpose.

     

    However you noticed that this maybe wouldn't be the way to go to "mess with personal calendars". So let we rephrase the solution i am looking for:

     

    One company wide calendar where employee's can see what's planned for them but also for there colleague's (without using planner assist in outlook). Currently we have our own desktop application where an employee can plan activities and we use a google account for a user friendly read-only iFrame of that calendar. However this no longer fits in the new workflow/ security policy.

     

    For this to work i see two options at the moment:

     

    Option 1:

    1. Create Shared Mailbox
    2. Link shared mailbox to the employee's (can this be automated?) with read and write permissions
    3. Educate employee's they have to use that calendar to add their appointments to. 
    4. At this stage they have two calendars, one personal and one company wide.

    The downside of this option is point 2 where we have to educate employee's to use a different method. (i know, changes....) I foresee that they will forget to add/update/remove appointments/ meetings in the company wide (shared mailbox) calendar.

     

    Option 2:

    1. Create Shared Mailbox
    2. Link shared mailbox to the employee's (can this be automated?) with read-only permissions
    3. Create App/ Flow that
      1. Loops through every employee (if possible in AD group)
      2. Check if there are new / changed / deleted events
      3. If changes are detected then update the shared calendar
      4. At this stage they have two calendars, one personal and one read-only company wide.

    I like this idea more because it's automated and therefore less likely to go wrong. For example an employee receives an external teams meeting and accepts it. But it forgets to add it manually (option 1) to add to the company wide calendar that another employee could plan something for him because he see's he's free (Of course the planning assistant would detect but we are a small company). This would be a problem because in Option 2 the App/ Flow would detect the newly created teams meeting and will add it to the company wide calendar automatically.

     

    I did some testing and it looks like i can make a Power Automate flow for this to work, however this flow only works for one user. As far as i know a flow cannot run at tenant level, right?

     

    Hopefully above makes sense and you guys have some tips for me to solve this puzzle 😉

  • eliotcole Profile Picture
    4,363 Moderator on at

    Yes, I think you're right to go with option 2, but also you can add the events into the employees own calendars as and when they're made in the group one, and not have to have them have the group one in their Outlook at all.

     

    I think that's what my linked/quoted solution was more about.

     

    The thing that you should probably build in, is some kind of sensitivity logic to the users' own calendar events. By which I mean you have a flow which creates the events in all staff member's calendars but with the following logic/caveats:

    1. A new event is made in the calendar.

    2. Flow begins with a String variable called eventStatusVAR.

    3. Flow determines if each user has any of the following and sets eventStatusVAR to:
      1. onsiteMtOvr - An onsite meeting overlapping
      2. onsiteMtNr - An onsite meeting beginning/ending within a short period around said meeting (eg 5-10m)
      3. offsiteMtOvr - An offsite meeting overlapping
      4. offsiteMtNr - An offsite meeting beginning/ending within a longer period around said meeting (eg 1-2hr)
      5. ooo - Is out of the office

    4. Inside the Apply to each for all staff users, the flow uses a Switch action based on the eventStatusVAR value for determining how to build the event graph call for that user.

      For example on ooo, they will not have an event made, or perhaps they will, but with no attendance.

     

    This is not perfect, and I've not addressed (here) ensuring that the user's event, and the all staff event, are the same thing, however I hope that's covered in my linked solution! 😅 If not, I'd imagine that it's just a slight amendment, just browse through the graph docs on it. Hmmm ... headache. 🤔

     

    Either way, doing it this way you can ensure that their attendance to the meeting will either be for sure (if they're in the office), or you'll know they might be late, or attend remotely, or not at all. Plus you can add reminders, notifications, etc, all via the graph call.

  • TripleNico Profile Picture
    8 on at

    @eliotcole Thanks again for your detailed reply. I will give it a try with Graph. Looking at the documentation it should work what i would like to do.

     

    The only thing that's unclear to me if such a flow can run at a tenant level or do i have to create a new user (FlowUser) that runs that flow and has the right privileges to do so?

  • eliotcole Profile Picture
    4,363 Moderator on at

    It's a good point ... there should be a service worker Flow account at the company as a matter of course, because the licencing woes are real these days.

     

    It shouldn't be too hard to sort the permissions out if it *is* an issue ... however hopefully this can be done without that. 👍

     

  • TripleNico Profile Picture
    8 on at

    Thanks for the help so far, will let you know when it's finished. Or if i need more help 😉

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard