Power Platform / M365 – Power Automate – Searching Office 365 user

Hi All,
Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂
Background : We were automating the process of inviting user to Azure AD and then adding respective user to given group. Here while before adding / inviting user to Azure AD we want to check if user is already exists or not. To check if user is already exist / invited we are using Search action from O365 user connection. So sharing how we were doing 🙂
Connection required – Office 365 Users
Office 365 Users Connection provider lets us access user profiles in our organization using our M365 account. We can have various actions such as get our profile, a user’s profile, a user’s manager or direct reports and also update a user profile.
Creating Office 365 Users connection :
- Navigate to “Power Automate”
- From left side pane, navigate to “Data >> Connections” – we will be redirected to connections page – https://india.flow.microsoft.com/manage/environments/Default-6b38e1c3-a1fe-40cc-8b93-a4159a50592c/connections
- On connections page, in left top corner we have an option “+ New connection” to create new connection as shown in below Fig
- From the given connections list, search for “Office 365” or if it already listed then please click on “+” icon which is in-front of connection name as shown in below fig
- Once we have clicked on “+” icon to create new “Office 365 Users“, we will have dialog which depicts short description for “Office 365 Users” connection and “Create” option as shown in below fig
- As shown in above Fig, on click of “Create” button, we will get an prompt for authenticating to Office 365 as
- Once we authenticated successfully, “Office 365 Users” connector will be added successfully as shown in below fig

Power Automate to check
- Now we are ready to use “Office 365 Users” action in our Power Automate
- Here, for demo purpose we will trigger our Power Automate manually
- Lets create Power Automate with manual action – “Manually trigger a flow“
- Add “Search for users (v2) action” as shown in below fig
- “Search for users (v2)” action takes “Search term” as input where possible values are – display name of user, surname, mail , mail nickname of user
- Here for demo purpose, I’ll give my email id
- Also since we know we have unique email id for each user we will specify value : 1 in Top column as shown in below fig so that we will get only one result 🙂
- “Search for users (v2)” this action returns array of users who get searched
- Lets trigger our Power Automate manually
- Once we got the result we could check if result returned or not as shown in below fig
How to check if we got the result or whether user is searched or not
- If we check the JSON response received
"body": {
"value": [
{
"Id": "ff594132-b1a6-4bd3-92e5-1d4621ca9180",
"AccountEnabled": true,
"BusinessPhones": [
"4250000000"
],
"DisplayName": "Prasham Sabadra",
"GivenName": "Prasham",
"Mail": "prasham@knowledgejunction1.onmicrosoft.com",
"MailNickname": "prasham",
"Surname": "Sabadra",
"UserPrincipalName":"prasham@knowledgejunction1.onmicrosoft.com"
}
]
}
- We have “body” element having array of “value” which contains list of users found.
- So if the length of “value” element is 1 or greater than 1 then we have result, we could check this by
length(outputs('Search_for_users_(V2)')?['body/value']) "is greater than or equal to 1"
- In this way we could easily get to know whether respective user is available in tenant or not
Thanks for reading 🙂 If its worth at least reading once, kindly please like and share 🙂 SHARING IS CARING 🙂
Enjoy the beautiful life 🙂 Have a FUN 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂
You must be logged in to post a comment.