[英]Active directory migration with powershell
我需要从AD Windows2003Forest迁移到AD2016。我具有以下脚本来批量创建用户。 我的要求是将旧广告的相同SID映射到新广告。 例如,在较旧的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,这是由域控制器基于RID生成的。 如果尝试迁移到新林,则需要执行适当的AD迁移。 旧的SID将被复制到迁移的用户的SID历史记录属性中,以允许基于旧SID的权限仍然有效。
如果您只是想升级到AD的较新版本,则最好将新的域控制器加入到现有的Active Directory林/域中。 森林功能级别必须为2003或更高。
作为附带说明,我建议您尽快删除2003服务器,因为Microsoft不再支持这些服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.