“I’d like to check whether a user with specific email address exists in our company’s Active Directory, can I use Power Automate to do that?”
When you’re working with email addresses, there’s always a difference whether it’s an internal or an external address. If it belongs to a user from your company, you can retrieve all his information from the Active Directory. On the other side, external email address is all you get, there’s no place to learn more about the user. But how do you check whether the user belongs to your company or not? Whether you can get this extra information?
Use ‘Run after’ after the ‘Get user profile’ action
If you know the user email address or his id, you can use the ‘Get user profile’ action. The small problem with this action is that it’ll fail for non-existing users.
But you can take it as a valid result (as when updating files) using the ‘Configure run after’ settings on the following actions.
Set the action to run after the ‘Get user profile’ has failed and define what to do when the user doesn’t exist.
Search for the user with an HTTP request
The second option, if you don’t want to deal with the ‘Run after’ settings, is to use an HTTP request. As explained in the previous article, you can search for a user using more properties than just his email or id. The HTTP request won’t fail for non-existing users, it’ll return either the user or an empty array.
Method: GET Uri: https://graph.microsoft.com/v1.0/users?$filter=<property> eq '<value>'
Check whether the output is empty (user doesn’t exist) or not (user exists), and continue accordingly.
You’ve got two options how to check whether a user exists using Power Automate – a dedicated action or an http request. If you use the dedicated action, you’ll have all the information available as dynamic content, but you must use the not so common ‘run after’ settings. The HTTP request evaluation is simpler with a condition, on the other side you must extract the user information from the response JSON.