如何从天蓝色广告中获取用户的公司域名

How to get company domain name for user from azure ad

如何从 Azure AD 中检索包含登录用户信息(包括域)的详细信息,例如 domain\useralias 以供用户输入?请注意,与 Azure AD 同步的 onprem 广告中有域名。

您可以使用 OnPremiseDistinguishedName 扩展 属性。

例子:-

    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]
    }
}