win10企业版加windows2019域控

1、powershell加域控

# 定义变量
$DomainName = "test.com"
#
$Credential = Get-Credential -Message "请输入域管理员凭据"

try {
    # 更改DNS服务器(如果需要且你知道DC的IP)
    # Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("192.168.1.10")

    # 执行加域操作
    if ($OU) {
        Add-Computer -DomainName $DomainName -Credential $Credential -OUPath $OU -Force -ErrorAction Stop
    } else {
        Add-Computer -DomainName $DomainName -Credential $Credential -Force -ErrorAction Stop
    }
    
    Write-Host "[SUCCESS] 计算机已成功加入域 $DomainName" -ForegroundColor Green
    
    # 询问是否重启
    $restart = Read-Host "是否立即重启计算机?(Y/N)"
    if ($restart -eq 'Y' -or $restart -eq 'y') {
        Restart-Computer -Force
    }
} catch {
    Write-Host "[ERROR] 加入域失败: $_" -ForegroundColor Red
    # 可以在这里添加更详细的错误日志记录
}

 

posted @ 2025-12-25 17:27  hopeccie  阅读(2)  评论(0)    收藏  举报