Secrets behind SharePoint Online – How to get Tenant & User’s AD ID

Published by Shantha Kumar on

Sometimes, we may want to get the current user’s Active Directory ID and Tenant ID. To get that we no need to write blah.. blah.. codes and scripts to get that. I’ll give you the quick tip on how quickly get that information.

The Current user’s Active Directory ID and Tenant ID always present in the SharePoint Page context. To get it instantly, just open the Developer Tools from the Browser and open the Console tab in the non-modern page. Then paste the below lines to get that,

 console.log("User ID: "+ _spPageContextInfo.aadUserId+ " - Tenant ID: " + _spPageContextInfo.aadTenantId); 

The modern page doesn’t provide the current context to end users by default. Unless we write SPFx web parts/extensions. You can check out the article How To Get Current Context From SharePoint Modern Site PageĀ to get the snippet to achieve it.

Use the below snippet which helps to get the User ID and Tenant ID in any pages in SharePoint.


Leave a Reply

Your email address will not be published. Required fields are marked *