Pallavi Muppidi
Pallavi Muppidi

Reputation: 35

How to get company domain name for user from azure ad

How to retrieve details which contains information of login user including domain for example let say domain\useralias from Azure AD for a user input? Note that domain names are there in onprem ad which were sync to Azure AD.

Upvotes: 1

Views: 1318

Answers (1)

You can use the OnPremiseDistinguishedName extension property.

Example:-

    foreach($line in Get-Content c:\users\myuser\users.txt) {
    if($line -match $regex){
        $onPremisesDistinguishedName = (Get-AzureADUserExtension -ObjectId $line).get_item("onPremisesDistinguishedName")
        $domain = $onPremisesDistinguishedName.split(",")
        $alias = $line.Split("@")
        $sAMAccountName = ($domain[2]).Substring(3)
        $sAMAccountName + "\" + $alias[0]
    }
}

Upvotes: 1

Related Questions