【发布时间】:2016-09-10 19:33:50
【问题描述】:
我对此脚本进行了一些修改。 UserID 通常是用户的名字后跟他们的姓氏。 我需要做的是在创建之前比较与每个用户名关联的代理地址和 SAMAccountName 属性。 所以我的意思是说 Jack Sparrow ,如果 jsparrow 已经在使用,那么脚本将尝试作为 jasparrow (名字的第一个和第二个字母)并且在使用中的 jasparrow 也会是 jacsparrow 等等。我想避免重复的用户名。 2-我决定使用 FirstName 的前两个字母、day/month 和 Lastname 的前两个字母来制作“有趣”的密码会更好。最终的结果是用户得到一个类似“Ja1009Sp”的密码。
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){
$useritems=@{
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
}
【问题讨论】:
-
仅供参考,您的脚本将生成“JackS”,而不是“JSparrow”作为用户名
-
感谢老兄,其实我知道这一点。顺便说一句,您对我的问题有任何答案吗?
-
如果它们都在使用中,包括
JackSparrow怎么办?
标签: windows powershell csv