当前位置: 移动技术网 > 科技>操作系统>windows > Windows Server 2016-批量新建域用户(二)

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

2019年02月21日  | 移动技术网科技  | 我要评论

张永明杀人动机,北半球小夏季是,东莞服务器

前几个章节我们讲到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}]

注解:

<userdn>:需要。指定要添加的用户的可分辨名称。如果省略专有名称,dsadd将从标准输入(stdin)中获取名称。
-samid <samname>:将安全帐户管理器(sam)名称指定为此用户的唯一sam帐户名称,例如,linda。如果未指定sam名称,dsadd将尝试使用userdn的公用名(cn)值中的前20个字符来创建sam帐户名。
-upn <upn>:指定要添加的用户的用户主体名称,例如xiaowen@azureyun.local
-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)(例如,xiaowen@azureyun.com)
-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

例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

net user批量创建域用户:

for /l %a in (1,1,10) do net user ts%a p@ssw0rd /add /domain

注解:(1,1,10)分别对应(开始值,递增量,终值),如果想递减(10,-1,1),ts%a 是用户名,p@ssw0rd是密码,密码必须符合复杂性要求。

 

active directory用户和计算机查看已创建用户:


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 cs001@azureyun.local –givename 001 –surname cs –displayname cs001 –path "ou=syncall,dc=azureyun,dc=local"

查看当前已有用户:

get-aduser –filter * |select name

 powershell批量创建测试域用户:

$password = "p@ssw0rd"
$securepassword = $password | convertto-securestring -asplaintext -force
1..10 |foreach-object {new-aduser -name "hp$_" -samaccountname "hp$_" -userprincipalname hp$_@azureyun.local  -path  "ou=helpdesk,dc=azureyun,dc=local" -accountpassword $securepassword -enabled $true -changepasswordatlogon $false}

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

get-aduser –filter * |select name

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网