简体   繁体   English

使用Powershell进行Active Directory迁移

[英]Active directory migration with powershell

I need to migrate from AD Windows2003Forest to AD 2016. I have below script to create users in bulk. 我需要从AD Windows2003Forest迁移到AD2016。我具有以下脚本来批量创建用户。 My requirement is to map the same SID of older AD to new AD. 我的要求是将旧广告的相同SID映射到新广告。 For example in older AD SID='xyz' then it should be the same in newAD too as SID='xyz' 例如,在较旧的AD SID ='xyz'中,则在newAD中也应该与SID ='xyz'相同

I am having all the users data along with SID in CSV format & am using below PowerShell script which is somehow not working. 我将所有用户数据以及CSV格式的SID一起使用,并且正在使用下面的PowerShell脚本,但该脚本无法正常工作。 As of advice or suggestions. 作为意见或建议。

powershell code snippent: 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)

       }
}

You won't be able to assign a SID as that's generated by the domain controller based on a RID. 您将无法分配SID,这是由域控制器基于RID生成的。 If trying to migrate to a new forest then you'll need to perform a proper AD migration. 如果尝试迁移到新林,则需要执行适当的AD迁移。 The old SIDs will be copied onto the migrated users' SID history attributes to allow permissions based on the old SID to still work. 旧的SID将被复制到迁移的用户的SID历史记录属性中,以允许基于旧SID的权限仍然有效。

If you simply want to upgrade to a newer version of AD then you're better off joining a newer domain controller to your existing Active Directory forest / domain. 如果您只是想升级到AD的较新版本,则最好将新的域控制器加入到现有的Active Directory林/域中。 The forest functional level mush be 2003 or higher. 森林功能级别必须为2003或更高。

As a side note, I'd recommend then getting rid of the 2003 servers as soon as possible as these are no longer supported by Microsoft. 作为附带说明,我建议您尽快删除2003服务器,因为Microsoft不再支持这些服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM