本教學課程會逐步引導您建立基本的 Active Directory 環境。
您可以使用您在教學課程中建立的環境來測試混合式身分識別案例的各種層面。 這是一些教學課程的必要條件。 如果您有現有的 Active Directory 環境,您可以使用該環境做為替代專案。 此資訊是為那些從零開始的人提供的。
先決條件
下列是完成此教學課程的必要條件
- 已安裝 Hyper-V 的電腦。 建議在 Windows 10 或 Windows Server 2022 計算機上執行此操作。
- 外部網路適配器,可讓虛擬機與因特網通訊。
- Azure 訂用帳戶
- Windows Server 2022 的複本
- Microsoft .NET Framework 4.7.1
備註
本教學課程使用PowerShell腳本,讓您可以以最快的時間建立教學課程環境。 每個腳本都會使用腳本開頭所宣告的變數。 您可以和應該變更變數以反映您的環境。
這些腳本會在安裝 Microsoft Entra Connect 雲端布建代理程式之前,先建立一般 Active Directory 環境。 它們與所有教學課程相關。
本教學課程中使用的PowerShell腳本複本 可在 GitHub 上取得。
建立虛擬機
您需要做的第一件事是建立虛擬機。 此虛擬機器被用作我們的內部部署 Active Directory 伺服器。 此步驟對於讓混合式身分識別環境啟動並執行至關重要。 執行下列動作:
- 以系統管理員身分開啟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 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 DVD Drive to Virtual Machine
Add-VMDvdDrive -VMName $VMName -ControllerNumber 0 -ControllerLocation 1 -Path $InstallMedia
#Mount Installation Media
$DVDDrive = Get-VMDvdDrive -VMName $VMName
#Configure Virtual Machine to Boot from DVD
Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive
完成作業系統的部署
若要完成虛擬機的建置,您必須完成作系統安裝。
- Hyper-V 管理員,在虛擬機上雙選
- 選取 [開始] 按鈕。
- 系統會提示您「按任何按鍵從 CD 或 DVD 開機」。 繼續這樣做。
- 在 Windows Server 啟動畫面上,選取您的語言,然後選取 [下一步] 。
- 選擇 立即安裝。
- 輸入您的授權金鑰,然後選取 [下一步] [下一步]。
- 核取 **我接受授權條款,然後選取 [下一步]。
- 選取 [自定義:僅安裝 Windows] (進階)
- 請選擇下一步
- 安裝完成後,請重新啟動虛擬機、登入並執行 Windows 更新,以確保 VM 是最 up-to日期。 安裝最新的更新。
安裝 Active Directory 必要條件
現在您已啟動虛擬機,您必須在安裝 Active Directory 之前先執行一些動作。 也就是說,您必須重新命名虛擬機、設定靜態IP位址和 DNS 資訊,以及安裝遠端伺服器管理工具。 執行下列動作:
- 以系統管理員身分開啟PowerShell ISE。
- 執行下列指令碼。
#Declare variables
$ipaddress = "10.0.1.117"
$ipprefix = "24"
$ipgw = "10.0.1.1"
$ipdns = "10.0.1.117"
$ipdns2 = "8.8.8.8"
$ipif = (Get-NetAdapter).ifIndex
$featureLogPath = "c:\poshlog\featurelog.txt"
$newname = "DC1"
$addsTools = "RSAT-AD-Tools"
#Set 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 環境
既然您已建立並重新命名已建立的 VM,而且其具有靜態 IP 位址,您可以安裝和設定 Active Directory 網域服務。 執行下列動作:
- 以系統管理員身分開啟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 AD DS, DNS and GPMC
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 New 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 使用者
既然您已擁有我們的 Active Directory 環境,您必須建立測試帳戶。 此帳戶會在我們的內部部署AD環境中建立,然後同步至 Microsoft Entra識別碼。 執行下列動作:
- 以系統管理員身分開啟PowerShell ISE。
- 執行下列指令碼。
# Filename: 4_CreateUser.ps1
# Description: Creates a user in Active Directory. This is part of
# the Azure AD Connect password hash sync tutorial.
#
# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This
# script is made available to you without any express, implied or
# statutory warranty, not even the implied warranty of
# merchantability or fitness for a particular purpose, or the
# warranty of title or non-infringement. The entire risk of the
# use or the results from the use of this script remains with you.
#
#
#
#
#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 租戶,以便將我們的使用者同步到雲端。 若要建立新的 Microsoft Entra 租戶,請執行下列動作。
- 登入 Microsoft Entra 系統管理中心 ,並使用具有您Microsoft Entra 訂用帳戶的帳戶登入。
- 選取 概觀。
- 選擇 [管理租戶]。
- 選取 建立。
- 提供 組織的名稱 以及 初始網域名稱。 然後選擇 [建立]。 這會建立您的目錄。
- 完成之後,請選取 這裡 連結來管理目錄。
在 Microsoft Entra ID 中建立混合式身分識別管理員
現在您已擁有 Microsoft Entra 租戶,接下來會建立混合身分識別系統管理員帳戶。 若要建立混合式身分識別系統管理員帳戶,請執行下列動作。
- 在 [管理] 底下,選取 [ 使用者]。
![顯示已選取 [使用者] 的 [概觀] 功能表螢幕快照。](../../../includes/governance/media/tutorial-single-forest/administrator-1.png)
- 選取 [所有使用者 ],然後選取 [+ 新增使用者]。
- 提供此使用者的名稱和用戶名稱。 這是租戶的混合身分識別管理員。 將 目錄角色 變更為 混合式身分識別系統管理員。 您也可以顯示暫時密碼。 完成時,請選取 [建立]。
- 完成之後,請開啟新的網頁瀏覽器,並使用新的混合式身分識別系統管理員帳戶和暫時密碼登入 myapps.microsoft.com。
- 將混合式身分識別系統管理員的密碼變更為您可以記住的密碼。
選擇性:另一部伺服器和樹系
以下是選擇性區段,提供建立另一部伺服器和或樹系的步驟。 這可用於某些更進階的教學課程,例如 Pilot for Microsoft Entra Connect 至雲端同步。
如果您只需要另一部伺服器,您可以在 - 建立虛擬機 步驟之後停止,並將伺服器加入您先前建立的現有網域。
建立虛擬機
- 以系統管理員身分開啟PowerShell ISE。
- 執行下列指令碼。
# Filename: 1_CreateVM_CP.ps1
# Description: Creates a VM to be used in the tutorial.
#
# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. #This script is made available to you without any express, implied or statutory warranty, not even the implied warranty of merchantability or fitness for a particular purpose, or the warranty of title or non-infringement. The entire risk of the use or the results from the use of this script remains with you.
#
#
#
#
#Declare variables
$VMName = 'CP1'
$Switch = 'External'
$InstallMedia = 'D:\ISO\en_windows_server_2016_updated_feb_2018_x64_dvd_11636692.iso'
$Path = 'D:\VM'
$VHDPath = 'D:\VM\CP1\CP1.vhdx'
$VHDSize = '64424509440'
#Create 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 DVD Drive to Virtual Machine
Add-VMDvdDrive -VMName $VMName -ControllerNumber 0 -ControllerLocation 1 -Path $InstallMedia
#Mount Installation Media
$DVDDrive = Get-VMDvdDrive -VMName $VMName
#Configure Virtual Machine to Boot from DVD
Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive
完成作業系統的部署
若要完成虛擬機的建置,您必須完成作系統安裝。
- Hyper-V 管理員,在虛擬機上雙選
- 選取 [開始] 按鈕。
- 系統會提示您「按任何按鍵從 CD 或 DVD 開機」。 繼續這樣做。
- 在 Windows Server 啟動畫面上,選取您的語言,然後選取 [下一步] 。
- 選擇 立即安裝。
- 輸入您的授權金鑰,然後選取 [下一步] [下一步]。
- 核取 **我接受授權條款,然後選取 [下一步]。
- 選取 [自定義:僅安裝 Windows] (進階)
- 請選擇下一步
- 安裝完成後,請重新啟動虛擬機、登入並執行 Windows 更新,以確保 VM 是最 up-to日期。 安裝最新的更新。
安裝 Active Directory 必要條件
既然您已啟動虛擬機,您必須先執行一些動作,再安裝 Active Directory。 也就是說,您必須重新命名虛擬機、設定靜態IP位址和 DNS 資訊,以及安裝遠端伺服器管理工具。 執行下列動作:
- 以系統管理員身分開啟PowerShell ISE。
- 執行下列指令碼。
# Filename: 2_ADPrep_CP.ps1
# Description: Prepares your environment for Active Directory. This is part of
# the Azure AD Connect password hash sync tutorial.
#
# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This
# script is made available to you without any express, implied or
# statutory warranty, not even the implied warranty of
# merchantability or fitness for a particular purpose, or the
# warranty of title or non-infringement. The entire risk of the
# use or the results from the use of this script remains with you.
#
#
#
#
#Declare variables
$ipaddress = "10.0.1.118"
$ipprefix = "24"
$ipgw = "10.0.1.1"
$ipdns = "10.0.1.118"
$ipdns2 = "8.8.8.8"
$ipif = (Get-NetAdapter).ifIndex
$featureLogPath = "c:\poshlog\featurelog.txt"
$newname = "CP1"
$addsTools = "RSAT-AD-Tools"
#Set 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 環境
既然您已建立並重新命名 VM,而且其具有靜態 IP 位址,您就可以安裝及設定 Active Directory 網域服務。 執行下列動作:
- 以系統管理員身分開啟PowerShell ISE。
- 執行下列指令碼。
# Filename: 3_InstallAD_CP.ps1
# Description: Creates an on-premises AD environment. This is part of
# the Azure AD Connect password hash sync tutorial.
#
# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This
# script is made available to you without any express, implied or
# statutory warranty, not even the implied warranty of
# merchantability or fitness for a particular purpose, or the
# warranty of title or non-infringement. The entire risk of the
# use or the results from the use of this script remains with you.
#
#
#
#
#Declare variables
$DatabasePath = "c:\windows\NTDS"
$DomainMode = "WinThreshold"
$DomainName = "fabrikam.com"
$DomaninNetBIOSName = "FABRIKAM"
$ForestMode = "WinThreshold"
$LogPath = "c:\windows\NTDS"
$SysVolPath = "c:\windows\SYSVOL"
$featureLogPath = "c:\poshlog\featurelog.txt"
$Password = "Pass1w0rd"
$SecureString = ConvertTo-SecureString $Password -AsPlainText -Force
#Install AD DS, DNS and GPMC
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 New 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 使用者
既然您已擁有我們的 Active Directory 環境,您需要測試帳戶。 此帳戶會在我們的內部部署AD環境中建立,然後同步至 Microsoft Entra識別碼。 執行下列動作:
- 以系統管理員身分開啟PowerShell ISE。
- 執行下列指令碼。
# Filename: 4_CreateUser_CP.ps1
# Description: Creates a user in Active Directory. This is part of
# the Azure AD Connect password hash sync tutorial.
#
# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This
# script is made available to you without any express, implied or
# statutory warranty, not even the implied warranty of
# merchantability or fitness for a particular purpose, or the
# warranty of title or non-infringement. The entire risk of the
# use or the results from the use of this script remains with you.
#
#
#
#
#Declare variables
$Givenname = "Anna"
$Surname = "Ringdal"
$Displayname = "Anna Ringdal"
$Name = "aringdal"
$Password = "Pass1w0rd"
$Identity = "CN=aringdal,CN=Users,DC=fabrikam,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
結論
現在您有可用於現有教學課程的環境,並測試雲端同步提供的其他功能。