Home > other >  Getting Azure AD Account information without powershell modules
Getting Azure AD Account information without powershell modules

Time:05-31

I am trying to set up an auto sync script for sharepoint. I got everything I need for the script other than a way to get a logged on user's email.

I will be using intune to deploy the script so of course I cant hardcode the user's email.

I would prefer not to install any powershell modules like AZ or AzureAD. Is there anyway to get information of a logged in AzureAD user (Email or user ID)?

I tried using $env:UserName but this gets me something I cant use.

CodePudding user response:

I've not tested this as I don't have Intune but there was a solution here:

https://www.reddit.com/r/Intune/comments/iy157m/how_to_get_email_of_primary_user_or_logged_in/

$guid = (Get-ItemProperty -Path "HKLM:SOFTWARE\Microsoft\Provisioning\OMADM\Accounts\*" -ErrorAction SilentlyContinue).PSChildname

$upn = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Enrollments\$GUID" -ErrorAction SilentlyContinue).upn
  • Related