如果名字和第二个名字重复,则不会创建AD帐户



我正在创建一个脚本,为我的一个客户(英国的NHS(在域上创建用户,但是如果用户有一个名字和第二个名字,它目前拒绝创建AD用户和交换帐户AD中已经存在。

我已经通过在用户名末尾添加一个数字(如果它们已经存在(来绕过用户名重复。但是,如果名字/第二个名字重复,则不会创建帐户。

$DisplayName = $Surname + " " + $GivenName
$Mail = $GivenName + "." + $Surname + "@" + "royalberkshire.nhs.uk"
$MailAlias = $GivenName + "." + $Surname + "@" + $DNSRoot2
$SInitial = $Surname[0]
$Initial = $GivenName[0]
$SAMAccountName = $Surname + "" + $Initial
$SAMAccountLower = $SAMAccountName.ToLower()
$UserPrincipalName = $Surname+$Initial
$HD = "U"
$HDir = "\RBHFILRED002"
$AC = "Users_01$"
$DH = "Users_02$"
$IM = "Users_03$"
$NS = "Users_04$"
$TZ = "Users_05$"
$Folder = if ($SInitial -in 'a','b','c'){$AC}
elseif ($SInitial -in 'd','e','f', 'g','h'){$DH}
elseif ($SInitial -in 'i','j','k', 'l','m'){$IM}
elseif ($SInitial -in 'n','o','p', 'q','r','s'){$NS}
else {$TZ}
$group1 = "zz Everyone"
$group2 = "Safeboot Domain Users"
$defaultname = $SAMAccountName
$email = $GivenName + "." + $Surname
$i = 1
cls
while ((Get-ADUser -Identity $SAMAccountName -ErrorAction SilentlyContinue) -ne $null) {
$SamAccountName = $defaultname + [string]$i
$Mail = $email + [string]$i + "@" + "royalberkshire.nhs.uk"
$i++
}
$NewUserParams = @{
Path                  = "OU=Users,OU=RBFT,DC=rbbh-tr,DC=nhs,DC=uk"
SamAccountName        = $SAMAccountName
Name                  = $DisplayName
DisplayName           = $DisplayName
GivenName             = $GivenName
Surname               = $Surname
EmailAddress          = $Mail
UserPrincipalName     = "$SAMAccountName@rbbh-tr.nhs.uk"
Title                 = $title
HomeDrive             = $HomeDrive
HomeDirectory         = "$HDir$Folder$SAMAccountName"
Description           = $Description
ChangePasswordAtLogon = $true
PasswordNeverExpires  = $false
AccountPassword       = $defpassword
Enabled               = $true
}
New-ADUser @NewUserParams
Add-ADGroupMember -Identity $group1  -Members $SAMAccountName
Start-Sleep -s 10
Add-ADGroupMember -Identity $group2  -Members $SAMAccountName
cls
echo "Please Wait Whilst We Find The AD Account & Create The Exchange Mailbox.."
Start-Sleep -s 30
Enable-Mailbox -Identity $SAMAccountName
cls

有什么想法吗?

编辑 1 - 错误输出:

名称 : Microsoft.Exchange.Management.PowerShell.E2010 PSVersion : 1.0 说明 : Exchange 服务器的管理任务 名称 : Microsoft.Exchange.Management.Powershell.Support PSVersion : 1.0 说明 : Exchange Server 的支持任务 此工具将用于在 RBFT 域下创建用户帐户 仅限终极业务解决方案。如果适用,请点击任意键继续。 Get-ADUser:找不到具有标识为"TimmsJ1"的对象:"DC=rbbh-tr,DC=nhs,DC=uk"。at C:\Users\timmsj\Desktop\Scripts\User_Creation\RBFT_UC_Dev.ps1:140 char:9 + while ((get-ADUser -identity $SAMAccountName -errorAction silentlyCon ... +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (TimmsJ1:ADUser( [Get-ADUser], ADIdentityNotFoundException + FullQualifiedErrorId : 找不到具有标识的对象: 'TimmsJ1' u nder: 'DC=rbbh-tr,DC=nhs,DC=uk'.,Microsoft.ActiveDirectory.Management.Comm ands.GetADUser New-ADUser:尝试将名称已在 C:\Users\timmsj\Desktop\Scripts\User_Creation\RBFT_UC_Dev.ps1:166 字符:1 的目录中添加对象 + 新ADUser @NewUserParams + ~~~~~~~~~~~~~~~~~~~~~~~~~ + 类别信息 : 未指定: (CN=蒂姆斯·詹姆斯,...tr,DC=nhs,DC=uk:String( [New-ADUser], ADException + FullQualifiedErrorId:尝试使用已在使用的名称将对象添加到 dire ctory 中,Microsoft.ActiveDirectory.Managem ent。Command.NewADUser Add-ADGroupMember : 找不到具有标识为"TimmsJ1"的对象,在:"DC=rbbh-tr,DC=nhs,DC=uk"下。 at C:\Users\timmsj\Desktop\Scripts\User_Creation\RBFT_UC_Dev.ps1:167 char:1 + 添加广告组成员 -身份 $group 1 -成员 $SAMAccountName + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (TimmsJ1:ADPrincipal( [Add-ADGro upMember], ADIdentityNotFoundException + FullQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Micros oft.ActiveDirectory.Management.Command.AddADGroupMember Add-ADGroupMember : 在以下位置找不到具有标识为"TimmsJ1"的对象: 'DC=rbbh-tr,DC=nhs,DC=uk'.at C:\Users\timmsj\Desktop\Scripts\User_Creation\RBFT_UC_Dev.ps1:169 char:1 + 添加广告组成员 -身份 $group 2 -成员 $SAMAccountName + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (TimmsJ1:ADPrincipal( [Add-ADGroupMember], ADIdentityNotFoundException + FullQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Command.AddADGroupMember 请稍候,我们找到AD帐户并创建交换邮箱。 启用邮箱:无法执行该操作,因为在"rbhdc8red002.rbbh-tr.nhs.uk"上找不到对象"TimmsJ1"。 at C:\Users\timmsj\Desktop\Scripts\User_Creation\RBFT_UC_Dev.ps1:175 char:1 + 启用邮箱 - 身份$SAMAccountName + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 类别信息 : 未指定: (0:Int32( [启用邮箱], 管理 mentObjectNotFoundException + 完全限定错误 ID : 637D7B43,Microsoft.交换.管理.收件人任务.启用邮箱 用户名: 蒂姆斯J1 密码: 欢迎光临123 电子邮件: James.Timms1@royalberkshire.nhs.uk 职位名称 - 部门: 测试 - 终极 主目录: \\RBHFILRED002\Users_05$\TimmsJ1 您需要手动设置新用户的组成员身份。请这样做 在发送用户的帐户详细信息之前。 按任意键关闭

>参数-Name不仅设置属性name,还设置cn(公用名(,它必须像sAMAccountName一样是唯一的。要解决此问题,请更改以下内容:

$NewUserParams = @{
Path                  = "OU=Users,OU=RBFT,DC=rbbh-tr,DC=nhs,DC=uk"
SamAccountName        = $SAMAccountName
Name                  = $DisplayName
DisplayName           = $DisplayName
...
}

进入这个:

$NewUserParams = @{
Path                  = "OU=Users,OU=RBFT,DC=rbbh-tr,DC=nhs,DC=uk"
Name                  = $SAMAccountName
DisplayName           = $DisplayName
...
}

省略-SamAccountName参数的值-Name也会自动断言为sAMAccountName

相关内容

  • 没有找到相关文章

最新更新