使用Powershell 脚本建立AD用户!

本文介绍如何使用Powershell脚本创建Active Directory用户,包括必填字段配置及导入CSV文件的操作流程。

我在前面写过一篇使用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:

OK 接下里我们要通过POWERSHELL 命令来达到我们的目标,具体的Powershell命令如下:

接下来我们按回车之后,用户被一个一个的导入,我们接下来查看用户导入状态,找到用户所在的OU,刷新下,我们即可完成用户的新建过程:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雾岛心情

欢迎你的打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值