创建域用户 New-ADUser 脚本

Steven · 2023-03-30 22:49 · 66 views · Active Directory · old id 159


# 设置变量
$Username = "NewUser"
$Password = ConvertTo-SecureString "Password123" -AsPlainText -Force
$FirstName = "John"
$LastName = "Doe"
$Email = "johndoe@example.com"
$Department = "IT"
$Title = "Engineer"

# 创建用户
New-ADUser -Name $Username -SamAccountName $Username -AccountPassword $Password -Enabled $true -GivenName $FirstName -Surname $LastName -EmailAddress $Email -Department $Department -Title $Title -Path "OU=Users,DC=example,DC=com"


在上面的脚本中,变量$Username用于指定用户名,$Password用于指定密码。$FirstName和$LastName用于指定用户的名字和姓氏,$Email用于指定用户的电子邮件地址,$Department用于指定用户所在的部门,$Title用于指定用户的职位。

使用New-ADUser命令来创建用户,使用-SamAccountName参数来指定用户的登录名。-AccountPassword参数用于指定密码,-Enabled参数用于启用用户账户。-GivenName和-Surname参数用于指定用户的名字和姓氏,-EmailAddress参数用于指定电子邮件地址,-Department参数用于指定部门,-Title参数用于指定职位。-Path参数用于指定用户的所在的 OU 的路径。


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>]


← Back to home