以下是工作电脑加入 Active Directory 域步骤,涵盖图形界面和命令行操作,适用于 Windows 10/11 系统:
一、加域前置条件
1. 网络环境准备
- 确保电脑与域控制器网络连通(同一 VLAN 或 VPN 内网穿透)
- DNS 配置:
✅ 验证命令:# 设置主 DNS 为域控 IP(示例) Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).ifIndex -ServerAddresses ("192.168.1.10", "192.168.1.11")
nslookup corp.contoso.com
应返回域控 IP
2. 本地管理员权限
- 以本地管理员身份登录(非标准用户账号)
- 禁用第三方防火墙/安全软件(临时)
3. 域信息获取
- 域名:
corp.contoso.com
(全称) - NetBIOS 域名:
CORP
(通常为域名首段大写) - 域管理员账号:
admin@corp.contoso.com
(或CORP\admin
)
二、图形界面加域流程
步骤 1:打开系统属性
- 快捷键:
Win + R
→ 输入sysdm.cpl
→ 回车 - 导航:选择 计算机名 选项卡 → 点击 更改
步骤 2:输入域信息
-
选择 域 → 输入完整域名
corp.contoso.com
-
点击 确定 → 弹出凭据窗口
步骤 3:提供域管理员凭据
- 输入具备加域权限的账号(格式任选其一):
- User Principal Name (UPN):
admin@corp.contoso.com
- SAMAccountName:
CORP\admin
- 密码:对应账户密码
- User Principal Name (UPN):
步骤 4:完成加域与重启
- 成功提示:显示 “欢迎加入 corp.contoso.com 域”
- 强制重启:必须重启使组策略生效(
shutdown /r /t 0
)
三、PowerShell 加域(无 UI 操作)
1. 基础命令
# 定义安全密码对象
$Password = ConvertTo-SecureString "P@ssw0rd!" -AsPlainText -Force
# 创建凭据对象
$Credential = New-Object System.Management.Automation.PSCredential ("CORP\admin", $Password)
# 执行加域
Add-Computer -DomainName "corp.contoso.com" -Credential $Credential -Restart -Force
2. 高级参数
- 指定 OU 路径:
Add-Computer -OUPath "OU=Workstations,DC=corp,DC=contoso,DC=com"
- 更改计算机名:
Rename-Computer -NewName "PC-101" -DomainCredential $Credential -Force
四、加域后验证
1. 基础验证
- 命令检查:
systeminfo | Select-String "Domain" # 输出应为:Domain: corp.contoso.com
- 注册表验证:
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" | Select-Object ComputerName
2. 组策略应用验证
- 强制更新组策略:
gpupdate /force
- 检查策略结果:
gpresult /h C:\GPReport.html
3. 域用户登录测试
- 使用域账号登录(格式:
CORP\username
或username@corp.contoso.com
) - 验证网络驱动器映射/打印机自动部署
五、常见问题解决
❌ 错误 1:无法联系域控制器
- 排查步骤:
- 检查 IP/DNS 配置:
ipconfig /all
- 测试端口连通性:
Test-NetConnection 192.168.1.10 -Port 389 # LDAP Test-NetConnection 192.168.1.10 -Port 445 # SMB
- 验证时间同步:
w32tm /query /status
- 检查 IP/DNS 配置:
❌ 错误 2:权限不足
- 原因:
- 使用的账号无 将计算机加入域 权限
- 计算机账户数超过 AD 配额
- 解决方案:
# 检查账号权限 Get-ADUser -Identity admin -Properties "AllowedToJoinDomain" # 手动在 AD 中创建计算机对象(预授权) New-ADComputer -Name "PC-101" -SamAccountName "PC-101" -Path "OU=Workstations,DC=corp,DC=contoso,DC=com"
❌ 错误 3:重复计算机名
- 强制重命名:
Add-Computer -NewName "PC-102" -DomainName corp.contoso.com -Credential $Credential -Force
六、安全加固建议
- 限制本地管理员权限:
- 加域后移除本地管理员账号(保留 LAPS 管理)
- 启用 BitLocker:
Enable-BitLocker -MountPoint "C:" -EncryptionMethod XtsAes256 -UsedSpaceOnly
- 应用设备合规策略:
- 通过 GPO 禁用 USB 存储
- 强制启用 Windows Defender 实时保护
七、文档与审计
- 记录计算机属性:
Get-ADComputer -Identity "PC-101" -Properties * | Export-Csv -Path C:\ADComputers.csv
- 启用审核日志:
Auditpol /set /subcategory:"Computer Account Management" /success:enable /failure:enable
执行建议:
- 生产环境中建议通过 Microsoft Endpoint Configuration Manager (MECM) 或 Intune 批量部署加域
- 定期执行
Test-ComputerSecureChannel
验证域信任关系
通过以上流程,可确保工作电脑高效、安全地融入企业 AD 管理体系。遇到复杂问题时,优先使用 dcdiag
和 repadmin
工具进行域控端诊断,具体操作请参考微软相关操作文档。