教學課程:基本 Azure Active Directory 環境
本教學課程將逐步引導您建立基本的 Active Directory 環境。
您可以使用您在教學課程中建立的環境來測試混合式身分識別案例的各種層面。 這是一些教學課程的必要條件。 如果您有現有的 Active Directory 環境,您可以使用該環境做為替代專案。 此資訊是為那些從零開始的人提供的。
必要條件
下列是完成此教學課程的必要條件
- 已安裝 Hyper-V 的電腦。 建議您在 Windows 10 或 Windows Server 2016 電腦上執行此作業。
- 外部網路介面卡用於讓虛擬機器與網際網路通訊。
- Azure 訂閱
- Windows Server 2016 複本
- Microsoft .NET Framework 4.7.1
注意
此教學課程使用 PowerShell 指令碼,可讓您在最快的時間內建立教學課程環境。 每個指令碼都使用在指令碼開頭處宣告的變數。 您可以且應該變更變數以反映您的環境。
這些指令碼用來在安裝 Microsoft Entra Connect 雲端佈建代理程式之前,建立一般的 Active Directory 環境。 它們在所有指令碼中都通用。
您可以在 GitHub 上的這裡取得本教學課程中使用的 PowerShell 指令碼。
建立虛擬機器
您需要做的第一件事是建立虛擬機。 此虛擬機器被用作我們的內部部署 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 租戶,接下來會建立混合身分識別系統管理員帳戶。 如要建立混合式身分識別管理員帳戶,請執行下列動作。
- 在 [管理] 底下選取 [使用者]。
- 選取 [所有使用者 ],然後選取 [+ 新增使用者]。
- 提供此使用者的名稱和使用者名稱。 這是租戶的混合身分識別管理員。 將 目錄角色 變更為 混合式身分識別系統管理員。 您也可以顯示暫時密碼。 完成時,請選取 [建立]。
- 完成此動作之後,請開啟新的網頁瀏覽器,並使用新的混合式身分識別系統管理員帳戶與臨時密碼登入 myapps.microsoft.com。
- 將混合式身分識別系統管理員的密碼變更為您可以記住的密碼。
選擇性:另一個伺服器和樹系
以下是選用區段,提供建立另一個伺服器和/或樹系的步驟。 此區段可用於一些較進階的教學課程,例如 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
結論
現在您有一個可以用於現有教學課程的環境,可用來測試雲端同步所提供的其他功能。