Windows Server 2016-批量新建域用户(二)

前几个章节我们讲到Windows Server 2016-图形化新建域用户(一),本章节我们简单讲解下如何通过命令批量创建域用户,以便高效完成日常工作中实际批量创建用户需求,内容涉及dsadd user、net user、new-aduser,具体信息如下:

dsadd user创建用户:

将单个用户添加到目录中。

Dsadd是Windows Server 2008中内置的命令行工具。如果您安装了Active Directory域服务(AD DS)服务器角色,则可以使用它。要使用dsadd,必须从提升的命令提示符运行dsadd命令。若要打开提升的命令提示符,请单击“ 开始”,右键单击“ 命令提示符”,然后单击“以管理员身份运行”

语法:dsadd user <UserDN> [-samid <SAMName>] [-upn <UPN>] [-fn <FirstName>] [-mi <Initial>] [-ln <LastName>] [-display <DisplayName>] [-empid <EmployeeID>] [-pwd {<Password> | *}] [-desc <Description>] [-memberof <Group> ...] [-office <Office>] [-tel <PhoneNumber>] [-email <Email>] [-hometel <HomePhoneNumber>] [-pager <PagerNumber>] [-mobile <CellPhoneNumber>] [-fax <FaxNumber>] [-iptel <IPPhoneNumber>] [-webpg <WebPage>] [-title <Title>] [-dept <Department>] [-company <Company>] [-mgr <Manager>] [-hmdir <HomeDirectory>] [-hmdrv <DriveLetter>:][-profile <ProfilePath>] [-loscr <ScriptPath>] [-mustchpwd {yes | no}] [-canchpwd {yes | no}] [-reversiblepwd {yes | no}] [-pwdneverexpires {yes | no}] [-acctexpires <NumberOfDays>] [-disabled {yes | no}] [{-s <Server> | -d <Domain>}] [-u <UserName>] [-p {<Password> | *}] [-q] [{-uc | -uco | -uci}]

注解:

dsadd user <UserDN> [-samid <SAMName>] [-upn <UPN>] [-fn <FirstName>] [-mi <Initial>] [-ln <LastName>] [-display <DisplayName>] [-empid <EmployeeID>] [-pwd {<Password> | *}] [-desc <Description>] [-memberof <Group> ...] [-office <Office>] [-tel <PhoneNumber>] [-email <Email>] [-hometel <HomePhoneNumber>] [-pager <PagerNumber>] [-mobile <CellPhoneNumber>] [-fax <FaxNumber>] [-iptel <IPPhoneNumber>] [-webpg <WebPage>] [-title <Title>] [-dept <Department>] [-company <Company>] [-mgr <Manager>] [-hmdir <HomeDirectory>] [-hmdrv <DriveLetter>:][-profile <ProfilePath>] [-loscr <ScriptPath>] [-mustchpwd {yes | no}] [-canchpwd {yes | no}] [-reversiblepwd {yes | no}] [-pwdneverexpires {yes | no}] [-acctexpires <NumberOfDays>] [-disabled {yes | no}] [{-s <Server> | -d <Domain>}] [-u <UserName>] [-p {<Password> | *}] [-q] [{-uc | -uco | -uci}]
<userDN>:需要。指定要添加的用户的可分辨名称。如果省略专有名称,dsadd将从标准输入(stdin)中获取名称。
-samid <SAMName>:将安全帐户管理器(SAM)名称指定为此用户的唯一SAM帐户名称,例如,Linda。如果未指定SAM名称,dsadd将尝试使用UserDN的公用名(CN)值中的前20个字符来创建SAM帐户名。
-upn <UPN>:指定要添加的用户的用户主体名称,例如[email protected]
-fn <FirstName>:指定要添加的用户的名字。
-mi <Initial>:指定要添加的用户的中间名首字母。
-ln <LastName>:指定要添加的用户的姓氏。
-display <DisplayName>:指定要添加的用户的显示名称。
-empid <EmployeeID>:指定要添加的用户的员工ID。
-pwd {<Password> | *}:指定将用户的密码设置为Password或星号(*)。如果将密码设置为*,则dsadd会提示您输入用户密码。
-desc <Description>:指定要添加的用户的描述。
-memberof <GroupDN>:指定希望用户成为其成员的组的可分辨名称。
-office <Office>:指定要添加的用户的办公室位置。
-tel <PhoneNumbe> :指定要添加的用户的电话号码。
-email <Email>:指定要添加的用户的电子邮件地址。
-hometel <HomePhoneNumber>:指定要添加的用户的家庭电话号码。
-pager <PagerNumber>:指定要添加的用户的寻呼机号码。
-mobile <CellPhoneNumber>:指定要添加的用户的手机号码。
-fax <FaxNumber>:指定要添加的用户的传真号。
-iptel <IPPhoneNumber>:指定要添加的用户的IP电话号码。
-webpg <WebPage>:指定要添加的用户的网页URL。
-title <Title>:指定要添加的用户的标题。
-dept <Department>:指定要添加的用户的部门。
-company <Company>:指定要添加的用户的公司信息。
-mgr <ManagerDN>:指定要添加的用户的管理员的可分辨名称。
-hmdir <HomeDirectory>:指定要添加的用户的主目录位置。如果将HomeDirectory指定为通用命名约定(UNC)路径,则必须使用-hmdrv参数为dsadd指定映射到此路径的驱动器号。
-hmdrv <DriveLetter>:指定要添加的用户的主目录驱动器号(例如,E :)。
-profile <ProfilePath>:指定要添加的用户的配置文件路径。
-loscr <ScriptPath>:指定要添加的用户的登录脚本路径。
-mustchpwd {yes| no}:指定用户下次登录时是否必须更改其密码。可用值为yes和no。默认情况下,用户不必更改密码(否)。
-canchpwd {yes| no}:指定用户是否可以更改其密码。可用值为yes和no。默认情况下,用户可以更改其密码(是)。如果-mustchpwd参数的值为yes,则此参数的值必须为yes。
-reversiblepwd {yes| no}:指定是否使用可逆加密存储用户密码。可用值为yes和no。默认情况下,用户无法使用可逆加密(否)。
-pwdneverexpires {yes| no}:指定用户密码是否永不过期。可用值为yes和no。默认情况下,用户密码到期(否)。
-acctexpires <NumberOfDays>:指定从今天起用户帐户将过期的天数。值为0表示今天结束时到期。正值设定将来到期。负值设置过去的到期时间。该值永远不会将帐户设置为永不过期。例如,值为0表示帐户在今天结束时到期。值-5表示该帐户已在5天前过期并设置过去的过期日期。值5将帐户到期日期设置为将来5天。
-disabled {yes| no}:指定dsadd是否禁用用于登录的用户帐户。可用值为yes或no。例如,以下命令在启用状态下创建Nicolettep用户帐户:
dsadd user CN=xxx,CN=Syncall,DC=azureyun,DC=Com -pwd Password123 -disabled no
{-s <Server> | -d <Domain>}:连接到指定的远程服务器或域。默认情况下,计算机连接到登录域中的域控制器。
-u <UserName>:指定用户登录到远程服务器的用户名。默认情况下,-u使用用户登录的用户名。您可以使用以下任何格式指定用户名:
用户名(例如,xiaowen)
域\用户名(例如,azureyun\xiaowen)
用户主体名称(UPN)(例如,[email protected]
-p {<Password> | *}:指定使用密码或*来登录远程服务器。如果键入*,系统将提示您输入密码。
-q:将所有输出抑制到标准输出(安静模式)。
{-uc | -uco | -uci}:指定输出或输入数据以Unicode格式化。以下列表说明了每种格式。
-uc:指定用于输入或输出到管道(|)的Unicode格式。
-uco:指定输出到管道(|)或文件的Unicode格式。
-uci:指定管道(|)或文件输入的Unicode格式。
/?:在命令提示符下显示帮助。

例1:在azureyun.local的syncall用户容器中创建名为cs002的已启用用户帐户

dsadd user CN=cs002,OU=Syncall,DC=azureyun,DC=local -disabled no

例2:创建名为cs003的启用用户帐户,密码为P@ssw0rd,必须在首次登录时更改密码:

dsadd user “CN=cs002,OU=Syncall,DC=azureyun,DC=local” -disabled no –pwd P@ssw0rd -mustchpwd yes

扫描二维码关注公众号,回复: 5239526 查看本文章

例3:创建cs004帐户,并设置密码永不过期,并使其成为同一OU中的AAA组的成员

dsadd user “CN=cs004,OU=Syncall,DC=azureyun,DC=local” -disabled no –pwd P@ssw0rd -mustchpwd yes -memberof CN=AAA,OU=Group,OU=Syncall,DC=azureyun,DC=local -acctexpires never

2018-02-05_00024

net user批量创建域用户:

for /L %a in (1,1,10) do net user TS%a P@ssw0rd /add /domain

2018-02-05_00026

Active Directory用户和计算机查看已创建用户:

2018-02-05_00028


New ADUser创建域帐号

语法:New-ADUser [-WhatIf][-Confirm][-AccountExpirationDate <DateTime>][-AccountNotDelegated <Boolean>][-AccountPassword <SecureString>][-AllowReversiblePasswordEncryption <Boolean>][-AuthenticationPolicy <ADAuthenticationPolicy>][-AuthenticationPolicySilo <ADAuthenticationPolicySilo>][-AuthType <ADAuthType>][-CannotChangePassword <Boolean>][-Certificates <X509Certificate[]>][-ChangePasswordAtLogon <Boolean>][-City <String>][-Company <String>][-CompoundIdentitySupported <Boolean>][-Country <String>][-Credential <PSCredential>][-Department <String>][-Description <String>][-DisplayName <String>][-Division <String>][-EmailAddress <String>][-EmployeeID <String>][-EmployeeNumber <String>][-Enabled <Boolean>][-Fax <String>][-GivenName <String>][-HomeDirectory <String>][-HomeDrive <String>][-HomePage <String>][-HomePhone <String>][-Initials <String>][-Instance <ADUser>][-KerberosEncryptionType <ADKerberosEncryptionType>][-LogonWorkstations <String>][-Manager <ADUser>][-MobilePhone <String>][-Name] <String>[-Office <String>][-OfficePhone <String>][-Organization <String>][-OtherAttributes <Hashtable>][-OtherName <String>][-PassThru][-PasswordNeverExpires <Boolean>][-PasswordNotRequired <Boolean>][-Path <String>][-POBox <String>][-PostalCode <String>][-PrincipalsAllowedToDelegateToAccount <ADPrincipal[]>][-ProfilePath <String>][-SamAccountName <String>][-ScriptPath <String>][-Server <String>][-ServicePrincipalNames <String[]>][-SmartcardLogonRequired <Boolean>][-State <String>][-StreetAddress <String>][-Surname <String>][-Title <String>][-TrustedForDelegation <Boolean>][-Type <String>][-UserPrincipalName <String>][<CommonParameters>]

例1:创建cs001帐号:

new-aduser –name cs001  -samaccountname cs001 –userprincipalname [email protected] –givename 001 –surname cs –displayname CS001 –path "OU=Syncall,DC=azureyun,DC=local"

查看当前已有用户:

get-aduser –filter * |select name

2018-02-05_00023

Powershell批量创建域用户:

$PlainPassword = "P@ssw0rd"
$SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force

1..10 |foreach-object {New-ADUser -Name "HP$_" -SamAccountName "HP$_" -UserPrincipalName [email protected]  -path  "OU=HelpDesk,DC=azureyun,DC=local" -AccountPassword $SecurePassword -Enabled $true -ChangePasswordAtLogon $false}

2018-02-05_00025

查看当前已创建域用户帐号:

2018-02-05_00027

猜你喜欢

转载自blog.51cto.com/wenzhongxiang/2352118