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

Power Automate - Result of "Search for users (V2) action
Power Automate - Result of "Search for users (V2) action

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 requiredOffice 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 :

  • On connections page, in left top corner we have an option “+ New connection” to create new connection as shown in below Fig
Power Automate - Connections - Creating new connection
Fig : Power Automate – Connections – Creating new connection
  • 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
Power Automate - Connections - Office 365 Users connection
Fig : Power Automate – Connections List – Selecting “Office 365 Users” to create new connection
  • 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
Power Automate - Connections List - Selecting "Office 365 Users" to create new connection
Fig : Power Automate – Connections List – Selecting “Office 365 Users” to create new connection
  • As shown in above Fig, on click of “Create” button, we will get an prompt for authenticating to Office 365 as
Power Automate - Connection to O365
Fig : Power Automate – Connection to O365
  • Once we authenticated successfully, “Office 365 Users” connector will be added successfully as shown in below fig
Power Automate - Connection to "Office 365 Users" get added successfully
Fig : Power Automate – Connection to “Office 365 Users” get added successfully

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 🙂
Power Automate - adding "Manually trigger a flow" action
Fig : Power Automate – adding “Manually trigger a flow” action and “Search for users (V2) action
  • 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
Power Automate - Result of "Search for users (V2) action"
Fig : Power Automate – Result of “Search for users (V2) action”
Power Automate - Result of "Search for users (V2) action" and checking for the result
Fig : Power Automate – Result of “Search for users (V2) action” and checking for the result

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 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading