分类: WINDOWS
2015-09-08 10:40:02
我在前面写过一篇使用For 语句和 dsquery 添加用户的例子,现在新版本的AD服务器出来后,我们现在可以使用Powershell 脚本来达成这个目标。我们要了解下Powershell的语法:
语法
New-ADUser [-Name] <string> [-AccountExpirationDate <System.Nullable[System.DateTime]>] [-AccountNotDelegated <Syst
em.Nullable[bool]>] [-AccountPassword <SecureString>] [-AllowReversiblePasswordEncryption <System.Nullable[bool]>]
[-AuthType {Negotiate | Basic}] [-CannotChangePassword <System.Nullable[bool]>] [-Certificates <X509Certificate[]>]
[-ChangePasswordAtLogon <System.Nullable[bool]>] [-City <string>] [-Company <string>] [-Country <string>] [-Creden
tial <PSCredential>] [-Department <string>] [-Description <string>] [-DisplayName <string>] [-Division <string>] [-
EmailAddress <string>] [-EmployeeID <string>] [-EmployeeNumber <string>] [-Enabled <System.Nullable[bool]>] [-Fax <
string>] [-GivenName <string>] [-HomeDirectory <string>] [-HomeDrive <string>] [-HomePage <string>] [-HomePhone <st
ring>] [-Initials <string>] [-Instance <ADUser>] [-LogonWorkstations <string>] [-Manager <ADUser>] [-MobilePhone <s
tring>] [-Office <string>] [-OfficePhone <string>] [-Organization <string>] [-OtherAttributes <hashtable>] [-OtherN
ame <string>] [-PassThru <switch>] [-PasswordNeverExpires <System.Nullable[bool]>] [-PasswordNotRequired <System.Nu
llable[bool]>] [-Path <string>] [-POBox <string>] [-PostalCode <string>] [-ProfilePath <string>] [-SamAccountName <
string>] [-ScriptPath <string>] [-Server <string>] [-ServicePrincipalNames <string[]>] [-SmartcardLogonRequired <Sy
stem.Nullable[bool]>] [-State <string>] [-StreetAddress <string>] [-Surname <string>] [-Title <string>] [-TrustedFo
rDelegation <System.Nullable[bool]>] [-Type <string>] [-UserPrincipalName <string>] [-Confirm] [-WhatIf] [<CommonPa
rameters>]
我们先编辑好相应的CSV文件,有几个选项是必选的,下面截图列出必选的条目,这里我们稍微解释下,samaccountname 是必选项,代表他登录的名称,Givenname和surname 分别是姓和名,Displayname 是显示名称,Path 代表的对象存放的OU: