How to Automatically Add a User to a Microsoft 365 Group on First Login
Question details
The user wants to automate the process of adding new users to a specific Microsoft 365 group the first time they sign in.

- Product
- Microsoft 365, Power Automate, Power Apps
- Device & OS
- not provided
- Scenario
- Onboarding new users and automatically assigning them to appropriate groups or workspaces upon their initial login.
- Observed behavior
- Power Automate lacks a native 'first sign-in' trigger, requiring a custom workaround utilizing Power Apps and Microsoft Graph to capture the event and update group membership.
Ensure you have Microsoft 365 administrative privileges, appropriate licensing for Power Apps and Power Automate, and the necessary API permissions to modify group memberships in Azure AD/Microsoft Entra ID.
Use Power Apps and Power Automate with Microsoft Graph API
Since Power Automate does not provide a standard trigger for a user's first sign-in, you can use a Power Apps login form to capture the user's ID and trigger a flow that adds them to the group via Microsoft Graph.
This workaround relies on establishing a Power App as the first point of entry for new users. When the user opens the app for the first time, it triggers a background flow that executes an API call.
Create a Power Apps canvas app and set it as the mandatory landing page for new users. Configure the app to automatically capture the current user's email address or User Principal Name (UPN) upon opening.
In Power Automate, create a new flow triggered by 'PowerApps'. This will allow the canvas app to pass the captured user credentials directly to your automation workflow.
Add an 'HTTP' action in your flow. Set the method to 'POST' and use the endpoint URI 'https://graph.microsoft.com/v1.0/groups/{group-id}/members/$ref', replacing '{group-id}' with your specific Microsoft 365 group ID.
In the HTTP action body, format the JSON payload to include the user's ID mapped from the Power Apps trigger: { "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{user-id}" }.
Return to your Power App, select the screen's 'OnVisible' property, and insert the command to run your flow, passing the User().Email as the required parameter.

Looking for a Lightweight Alternative to Microsoft Office?
While Microsoft 365 offers extensive enterprise automation like Power Apps and Microsoft Graph, many users simply need a powerful, easy-to-use suite for daily document creation. WPS Office provides a free, highly compatible alternative for Word, Excel, and PowerPoint files without the need for complex administrative workflows.

Frequently Asked Questions
Why isn't there a default Power Automate trigger for a user's first login?
Microsoft Power Automate relies on explicit audit logs or database events (like row creation) rather than an explicit 'first sign-in' user trigger. Using a Power App as the initial entry point is currently the most reliable workaround to capture this specific action.
Can I trigger a flow when a new user account is created instead of waiting for login?
Yes. If you do not strictly need the action to happen at first login, you can use the 'When a user is created' trigger in the Azure AD (Microsoft Entra ID) connector within Power Automate to immediately add them to a Microsoft 365 group.
What happens if a user who is already in the group triggers the Power App again?
The Microsoft Graph API will return a 400 Bad Request error stating the user is already a member. To prevent flow failures, you can add a 'Get member groups' action beforehand to check if the user is already in the group, or configure the HTTP action's 'Run after' settings to ignore the error.




