共用方式為


教學課程:基本 Azure Active Directory 環境

本教學課程將逐步引導您建立基本的 Active Directory 環境。

顯示基本 Microsoft Entra 環境的圖表。

您可以使用在本教學課程中建立的環境來測試混合式身分識別案例的各個層面,而且此環境將會成為部分教學課程的必要條件。 如果您已經有現有的 Active Directory 環境,可以用來做為替代方案。 本資訊是提供給從頭開始的人員參考。

必要條件

下列是完成此教學課程的必要條件

注意

此教學課程使用 PowerShell 指令碼,可讓您在最快的時間內建立教學課程環境。 每個指令碼都使用在指令碼開頭處宣告的變數。 您可以且應該變更變數以反映您的環境。

這些指令碼用來在安裝 Microsoft Entra Connect 雲端佈建代理程式之前,建立一般的 Active Directory 環境。 它們在所有指令碼中都通用。

您可以在 GitHub 上的這裡取得本教學課程中使用的 PowerShell 指令碼。

建立虛擬機器

您需要做的第一件事,就是建立將用作內部部署 Active Directory 伺服器的虛擬機器,以便讓我們的混合式身分識別環境開始執行。 執行下列操作:

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
#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 

完成作業系統部署

若要完成虛擬機器的建置,您必須完成作業系統安裝。

  1. 在 [Hyper-V 管理員] 中,按兩下虛擬機器
  2. 按一下 [開始] 按鈕。
  3. 系統會提示您「按任意鍵從 CD 或 DVD 開機」。 繼續執行。
  4. 在 Windows Server 啟動畫面上選取您的語言,然後按一下 [下一步]
  5. 按一下 [立即安裝]
  6. 輸入您的授權金鑰,然後按一下 [下一步]
  7. 選取 [我接受授權條款],然後按一下 [下一步]
  8. 選取 [自訂:只安裝 Windows (進階)]
  9. [下一步]
  10. 安裝完成之後,請重新啟動虛擬機器、登入並執行 Windows 更新,以確保 VM 為最新。 安裝最新的更新。

安裝 Active Directory 必要條件

現在您已啟動虛擬機器,必須在安裝 Active Directory 前做幾件事。 也就是說,您必須重新命名虛擬機器、設定靜態 IP 位址和 DNS 資訊,以及安裝遠端伺服器管理工具。 執行下列操作:

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
#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 Domain Services。 執行下列操作:

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
#Declare variables
$DatabasePath = "c:\windows\NTDS"
$DomainMode = "WinThreshold"
$DomainName = "contoso.com"
$DomaninNetBIOSName = "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 ID。 執行下列操作:

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
# 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 租用戶,請按照下列步驟操作。

  1. 登入 Microsoft Entra 系統管理中心,並使用具有 Microsoft Entra 訂用帳戶的帳戶進行登入。
  2. 按一下 [概觀]
  3. 按一下 [管理租用戶]
  4. 選取 [建立]
  5. 提供組織名稱初始網域名稱。 然後選取建立。 這將會建立您的目錄。
  6. 完成此動作之後,請按一下這裡以管理目錄。

在 Microsoft Entra ID 中建立混合式身分識別管理員

現在您已有 Microsoft Entra 租用戶,接下來將建立混合式身分識別系統管理員帳戶。 如要建立混合式身分識別管理員帳戶,請執行下列動作。

  1. 在 [管理] 底下選取 [使用者]
    此螢幕擷取畫面顯示已選取 [使用者] 的 [概觀] 功能表。
  2. 選取 [所有使用者],然後選取 [+ 新增使用者]
  3. 提供此使用者的名稱和使用者名稱。 這將成為您租用戶的混合式身分識別系統管理員。 建議您將 [目錄角色] 變更為 [混合式身分識別系統管理員]。您也可以顯示暫時密碼。 完成時,請選取 [建立]
  4. 完成此動作之後,請開啟新的網頁瀏覽器,並使用新的混合式身分識別系統管理員帳戶與臨時密碼登入 myapps.microsoft.com。
  5. 將混合式身分識別管理員密碼變更為您可以記住的密碼。

選擇性:另一個伺服器和樹系

以下是選用區段,提供建立另一個伺服器和/或樹系的步驟。 此區段可用於一些較進階的教學課程,例如 Microsoft Entra Connect 至雲端同步的試驗

如果您只需要另一個伺服器,可以在建立虛擬機器步驟之後停止,並將伺服器加入先前建立的現有網域。

建立虛擬機器

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
# 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

完成作業系統部署

若要完成虛擬機器的建置,您必須完成作業系統安裝。

  1. 在 [Hyper-V 管理員] 中,按兩下虛擬機器
  2. 按一下 [開始] 按鈕。
  3. 系統會提示您「按任意鍵從 CD 或 DVD 開機」。 繼續執行。
  4. 在 Windows Server 啟動畫面上選取您的語言,然後按一下 [下一步]
  5. 按一下 [立即安裝]
  6. 輸入您的授權金鑰,然後按一下 [下一步]
  7. 選取 [我接受授權條款],然後按一下 [下一步]
  8. 選取 [自訂:只安裝 Windows (進階)]
  9. [下一步]
  10. 安裝完成之後,請重新啟動虛擬機器、登入並執行 Windows 更新,以確保 VM 為最新。 安裝最新的更新。

安裝 Active Directory 必要條件

現在您已啟動虛擬機器,必須在安裝 Active Directory 前做幾件事。 也就是說,您必須重新命名虛擬機器、設定靜態 IP 位址和 DNS 資訊,以及安裝遠端伺服器管理工具。 執行下列操作:

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
# 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 Domain Services。 執行下列操作:

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
# 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 ID。 執行下列操作:

  1. 以系統管理員身分開啟 PowerShell ISE。
  2. 執行下列指令碼。
# 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

結論

現在您有一個可以用於現有教學課程的環境,可用來測試雲端同步所提供的其他功能。

下一步