このスクリプトにはいくつか変更があります。 UserIDは、通常、ユーザのファーストネームとそれに続くファーストネームです。 私がする必要があるのは、プロキシアドレス& SAMAccountName属性を作成する前に、各ユーザー名に関連付けられているものと比較することです。 だから、ジャススパロウと言うと、jsparrowが既に使用されていて、スクリプトがjasparrow(firstnameとfirstnameの第一文字)として試して、jasparrowを使うとjacsparrowなどになります。私は重複したユーザー名を避けたい。 2「名字」の最初の2文字、「姓」の最初の2文字を使用する「楽しい」パスワードを作成する方がよいと判断しました。最終的に、ユーザーは「Ja1009Sp」のようなパスワードを取得します。csvファイルを使用した重複した大量のADUserの作成を避ける
Firstname,LastName,Department,Manager,MobilePhone
Jack,Sparrow,IT,jsmith,1 88 635 5254-0551
John Smith,Sparrow,Finance,jsmith,188 635 5254-0554
スクリプト:
Import-Module ActiveDirectory
$UserList = Import-CSV -Path C:\Temp\CreateUsers.csv
$targetOU='OU=usersOU,DC=My,DC=Domain,DC=org'
$upnDomain='sec.local'
foreach($Person in $UserList){
[email protected]{
GivenName=$Person.Firstname
Surname=$Person.LastName
Department=$Person.Department
AccountPassword=ConvertTo-SecureString -String $Person.Password -AsPlainText -force
ChangePasswordAtLogon=$false
Enabled=$true
DisplayName="$($Person.Firstname) $($Person.Lastname)"
Manager=$Person.Manager
MobilePhone=$Person.MobilePhone
Name="$($Person.Firstname) $($Person.Lastname)"
SamAccountName="$($Person.Firstname+$Person.LastName.Substring(0,1))"
UserPrincipalName="$($Person.FirstName+$Person.LastName.Substring(0,1))@$upnDomain"
Company="Contoso"
}
New-ADUser @useritems -Path $targetOU
}
だけFYI、スクリプトはこの実際に私は認識して、ユーザ名 –
感謝の男として「ジャック」ではなく、「JSparrow」を生成します。あなたは私の質問に答えがありますか? – Arbelac
「JackSparrow」を含むすべてが使用されている場合はどうなりますか? –