Scenario:使用 Microsoft Entra Connect 同步功能管理已从 Active Directory 预配的云用户和组。
先决条件
- 安装了 Hyper-V 的计算机。 建议在 Windows 10 或 Windows Server 2016 计算机上安装Hyper-V。
- Azure订阅。 如果没有Azure订阅,请在开始前创建 Trial。
- 外部网络适配器,因此虚拟机可以连接到 Internet。
- Windows Server 2016的副本。
注意事项
本教程使用 PowerShell 脚本来快速创建教程环境。 每个脚本都使用在脚本开头声明的变量。 请务必更改变量以反映你的环境。
本教程中的脚本在安装 Microsoft Entra Connect 之前创建常规Windows Server Active Directory(Windows Server AD)环境。 相关教程中也会使用脚本。
本教程中使用的 PowerShell 脚本在 GitHub 上提供。
创建虚拟机
若要创建混合标识环境,第一个任务是创建用作本地Windows Server AD 服务器的虚拟机。
注意事项
如果从未在主机上的 PowerShell 中运行脚本,请在运行任何脚本之前,以管理员身份打开 Windows PowerShell ISE,并运行 Set-ExecutionPolicy remotesigned。 在 “执行策略更改 ”对话框中,选择“ 是”。
若要创建虚拟机:
以管理员身份打开 Windows PowerShell ISE。
运行以下脚本:
#Declare variables $VMName = 'DC1' $Switch = 'External' $InstallMedia = 'D:\ISO\en_windows_server_2016_updated_feb_2018_x64_dvd_11636692.iso' $Path = 'D:\VM' $VHDPath = 'D:\VM\DC1\DC1.vhdx' $VHDSize = '64424509440' #Create a new virtual machine New-VM -Name $VMName -MemoryStartupBytes 16GB -BootDevice VHD -Path $Path -NewVHDPath $VHDPath -NewVHDSizeBytes $VHDSize -Generation 2 -Switch $Switch #Set the memory to be non-dynamic Set-VMMemory $VMName -DynamicMemoryEnabled $false #Add a DVD drive to the virtual machine Add-VMDvdDrive -VMName $VMName -ControllerNumber 0 -ControllerLocation 1 -Path $InstallMedia #Mount installation media $DVDDrive = Get-VMDvdDrive -VMName $VMName #Configure the virtual machine to boot from the DVD Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive
安装操作系统。
若要完成创建虚拟机,请安装操作系统:
- 在Hyper-V管理器中,双击虚拟机。
- 选择 “开始”。
- 在提示符下,按任意键从 CD 或 DVD 启动。
- 在Windows Server开始窗口中,选择语言,然后选择 Next。
- 选择“ 立即安装”。
- 输入许可证密钥,然后选择“ 下一步”。
- 选中 “我接受许可条款 ”复选框,然后选择“ 下一步”。
- 选择Custom:仅安装Windows(高级)。
- 选择“下一步”。
- 安装完成后,重启虚拟机。 登录,然后检查Windows Update。 安装任何更新,确保虚拟机完全处于最新状态。
安装 Windows Server AD 先决条件
在安装 Windows Server AD 之前,请运行安装先决条件的脚本:
以管理员身份打开 Windows PowerShell ISE。
运行
Set-ExecutionPolicy remotesigned。 在“执行策略更改”对话框中,选择“全部为是”。运行以下脚本:
#Declare variables $ipaddress = "10.0.1.117" $ipprefix = "24" $ipgw = "10.0.1.1" $ipdns = "10.0.1.117" $ipdns2 = "4.2.2.2" $ipif = (Get-NetAdapter).ifIndex $featureLogPath = "c:\poshlog\featurelog.txt" $newname = "DC1" $addsTools = "RSAT-AD-Tools" #Set a static IP address New-NetIPAddress -IPAddress $ipaddress -PrefixLength $ipprefix -InterfaceIndex $ipif -DefaultGateway $ipgw # Set the DNS servers Set-DnsClientServerAddress -InterfaceIndex $ipif -ServerAddresses ($ipdns, $ipdns2) #Rename the computer Rename-Computer -NewName $newname -force #Install features New-Item $featureLogPath -ItemType file -Force Add-WindowsFeature $addsTools Get-WindowsFeature | Where installed >>$featureLogPath #Restart the computer Restart-Computer
创建Windows Server AD 环境
现在,安装和配置Active Directory Domain Services以创建环境:
以管理员身份打开 Windows PowerShell ISE。
运行以下脚本:
#Declare variables $DatabasePath = "c:\windows\NTDS" $DomainMode = "WinThreshold" $DomainName = "contoso.com" $DomainNetBIOSName = "CONTOSO" $ForestMode = "WinThreshold" $LogPath = "c:\windows\NTDS" $SysVolPath = "c:\windows\SYSVOL" $featureLogPath = "c:\poshlog\featurelog.txt" $Password = "Pass1w0rd" $SecureString = ConvertTo-SecureString $Password -AsPlainText -Force #Install Active Directory Domain Services, DNS, and Group Policy Management Console start-job -Name addFeature -ScriptBlock { Add-WindowsFeature -Name "ad-domain-services" -IncludeAllSubFeature -IncludeManagementTools Add-WindowsFeature -Name "dns" -IncludeAllSubFeature -IncludeManagementTools Add-WindowsFeature -Name "gpmc" -IncludeAllSubFeature -IncludeManagementTools } Wait-Job -Name addFeature Get-WindowsFeature | Where installed >>$featureLogPath #Create a new Windows Server AD forest Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath $DatabasePath -DomainMode $DomainMode -DomainName $DomainName -SafeModeAdministratorPassword $SecureString -DomainNetbiosName $DomainNetBIOSName -ForestMode $ForestMode -InstallDns:$true -LogPath $LogPath -NoRebootOnCompletion:$false -SysvolPath $SysVolPath -Force:$true
创建Windows Server AD 用户
接下来,创建测试用户帐户。 在on-premises Active Directory环境中创建此帐户。 然后,该帐户将同步到Microsoft Entra ID。
以管理员身份打开 Windows PowerShell ISE。
运行以下脚本:
#Declare variables $Givenname = "Allie" $Surname = "McCray" $Displayname = "Allie McCray" $Name = "amccray" $Password = "Pass1w0rd" $Identity = "CN=ammccray,CN=Users,DC=contoso,DC=com" $SecureString = ConvertTo-SecureString $Password -AsPlainText -Force #Create the user New-ADUser -Name $Name -GivenName $Givenname -Surname $Surname -DisplayName $Displayname -AccountPassword $SecureString #Set the password to never expire Set-ADUser -Identity $Identity -PasswordNeverExpires $true -ChangePasswordAtLogon $false -Enabled $true
创建 Microsoft Entra 租户
如果您没有租户,请按照文章 在 Microsoft Entra ID 中创建新租户 中的步骤创建一个新的租户。
在 Microsoft Entra ID 中创建混合标识管理员
下一个任务是创建混合标识管理员帐户。 此帐户用于在安装 Microsoft Entra Connect 期间创建Microsoft Entra连接器帐户。 Microsoft Entra连接器帐户用于将信息写入Microsoft Entra ID。
若要创建混合标识管理员帐户,请执行以下操作:
- 登录到 Microsoft Entra 管理中心。
- 浏览到 Entra ID>用户
- 选择“ 新建用户>创建新用户”。
- 在“创建新用户”窗格中,输入新用户的显示名称和用户主体名称。 你正在为租户创建混合标识管理员帐户。 你可以显示和复制临时密码。
- 在 “分配”下,选择“ 添加角色”,然后选择 “混合标识管理员”。
- 然后选择“查看 + 创建>”。
- 在新的 Web 浏览器窗口中,使用新的混合标识管理员帐户和临时密码登录
myapps.windowsazure.cn。
下载并安装 Microsoft Entra Connect
现在可以下载并安装 Microsoft Entra Connect 了。 安装后,你将使用快速安装。
转到 AzureADConnect.msi 并双击以打开安装文件。
在 “欢迎”中,选中复选框以同意许可条款,然后选择“ 继续”。
在“快速设置”中,选择“使用快速设置”。
在 Connect 到 Microsoft Entra ID 中,输入Microsoft Entra ID混合标识管理员帐户的用户名和密码。 选择“下一步”。
在 “连接到 AD DS”中,输入企业管理员帐户的用户名和密码。 选择“下一步”。
在 “准备配置”中,选择“ 安装”。
安装完成后,选择“退出”。
在使用同步服务管理器或同步规则编辑器之前,请先注销,然后再次登录。
在门户中查找用户
现在,您需要验证本地 Active Directory 租户中的用户是否已同步并且现在位于 Microsoft Entra 租户中。 此部分可能需要几小时才能完成。
若要验证用户是否已同步,请执行以下操作:
请以至少混合身份管理员的身份登录Microsoft Entra 管理中心。
浏览到 Entra ID>用户
验证租户中是否显示新用户。
使用用户帐户登录以测试同步
若要测试Windows Server AD 租户中的用户是否与Microsoft Entra租户同步,请以以下用户之一身份登录:
使用在我们的新租户中创建的用户帐户登录。
对于用户名,请使用格式
user@domain.partner.onmschina.cn。 使用用户用于登录on-premises Active Directory的相同密码。
已成功设置混合标识环境,可用于测试和熟悉Azure提供的内容。