【问题标题】:Active directory migration with powershell使用 powershell 迁移活动目录
【发布时间】:2018-09-21 07:24:10
【问题描述】:

我需要从 AD Windows2003Forest 迁移到 AD 2016。我有以下脚本可以批量创建用户。我的要求是将旧 AD 的相同 SID 映射到新 AD。例如,在旧 AD 中 SID='xyz' 那么它在 newAD 中也应该与 SID='xyz' 相同

我拥有所有用户数据以及 CSV 格式的 SID,并且正在使用以下 PowerShell 脚本,但不知何故无法正常工作。作为意见或建议。

powershell 代码片段:

#Enter a path to your import CSV file
$ADUsers = Import-csv C:\scripts\newusers.csv

foreach ($User in $ADUsers)
{

       $Username    = $User.username
       $Password    = $User.password
       $Firstname   = $User.firstname
       $Lastname    = $User.lastname
       $Department = $User.department
       $OU           = $User.ou
       $sid     = $User.sid
    $UserPrincipalName = $User.UserPrincipalName
    $DistinguishedName = $User.DistinguishedName

       #Check if the user account already exists in AD
       if (Get-ADUser -F {SamAccountName -eq $Username})
       {
               #If user does exist, output a warning message
               Write-Warning "A user account $Username has already exist in Active Directory."
       }
       else
       {
              #If a user does not exist then create a new user account

        #Account will be created in the OU listed in the $OU variable in the CSV file; don’t forget to change the domain name in the"-UserPrincipalName" variable
              New-ADUser `
            -SamAccountName $Username `
            -UserPrincipalName $UserPrincipalName `
            -Name "$Firstname $Lastname" `
            -GivenName $Firstname `
            -Surname $Lastname `
            -Enabled $True `
            -ChangePasswordAtLogon $True `
            -DisplayName "$Lastname, $Firstname" `
            -Department $Department `
        -DistinguishedName $DistinguishedName `
        -SID $sid `
            -Path $OU `
            -AccountPassword (convertto-securestring $Password -AsPlainText -Force)

       }
}

【问题讨论】:

  • 您不能分配这样的 SID。这是article about SIDs,但重要的部分是 RID 主“FSMO”角色(意味着 DC 生成 SID)。添加到此 SID 中包含域信息,因此如果您有一个新域,则不能有相同的 SID。这很好,因为您可能希望在迁移期间使用 SID 历史记录,以便在重建时保留旧权限。我还建议您使用 Microsoft 的 AD 迁移工具,而不是尝试手动编写脚本。

标签: powershell active-directory active-directory-group


【解决方案1】:

您将无法分配 SID,因为它是由域控制器基于 RID 生成的。如果尝试迁移到新的林,那么您需要执行正确的 AD 迁移。旧 SID 将被复制到迁移用户的 SID 历史属性中,以允许基于旧 SID 的权限仍然有效。

如果您只是想升级到较新版本的 AD,那么最好将较新的域控制器加入您现有的 Active Directory 林/域。森林功能等级必须为 2003 年或更高。

附带说明一下,我建议尽快删除 2003 服务器,因为 Microsoft 不再支持这些服务器。

【讨论】:

    猜你喜欢
    • 2022-09-23
    • 2015-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2018-02-12
    相关资源
    最近更新 更多