我正在尝试更新我域中的一些(560)用户。 根据我的工人DB,他们使用不完整和/或不正确的名字。
我创建了一个包含以下信息的CSV文件:
samaccoutname,Name,givenname,surname
r001248,ADRIANA DAS COUVE ,ADRIANA ,DAS COUVE
r020230,ALEXANDRA DAS NEVE ,ALEXANDRA ,DAS NEVE
这是我的代码,但它没有成功:
#
# Script.ps1
#
Import-Module activedirectory
$userlist = Import-Csv C:\Users\r013462\Documents\Atualização_AD.csv -Delimiter ","
foreach ($user in $userlist)
{
$GivenN = $user.givenName
$FullN = $user.Name
$SurN = $user.surName
Get-ADUser -Identity $user.samaccountname | Set-ADUser -GivenName $GivenN -Surname $SurN -DisplayName $FullN
}
建议?
答案 0 :(得分:0)
好的,最后,找到了解决方案!
如果你想这样做,你必须使用我发布的csv的相同参数并使用这个脚本:
#
# Script.ps1
#
Import-Module activedirectory
$varCSV = ""
$userlist = Import-Csv -Path $varCSV -Delimiter ","
foreach ($user in $userlist)
{
$samN = $user.samaccouNtname
$GivenN = $user.GivenName
$FullN = $user.Name
$SurN = $user.Surname
$dn = (Get-ADUser -Identity $samN).DistinguishedName
Get-ADUser -Identity $user.SamAccountName | Set-ADUser -GivenName $GivenN -SurName $SurN -DisplayName $FullN
Try {
Rename-ADObject $dn -NewName $FullN
}
catch {
Write-Output "usuario repetido: " ($user.samaccountname) | Out-File C:\errors.txt -Append
}
}