1. 建立文本文档另存为csv文件,注意编码格式,否则导入后是乱码

    wKiom1mx_rTgS1HaAADFk4mu5_g826.png-wh_50

    wKioL1mx_p_yOnNGAACMSY5P9Ww834.png-wh_50

  2. 使用powellshell命令导入

    Import-Csv -Path E:\users.csv | foreach { new-aduser -name $_.name -SamAccountName $_.samaccountname -GivenName $_.givenname -Surname $_.surname -DisplayName $_.displayname -Path $_.path -UserPrincipalName $_.userprincipalname -AccountPassword  (ConvertTo-SecureString -string  $_.accountpassword -AsPlainText -Force )  -Enabled $true -ChangePasswordAtLogon $false }

   3.查看建立的用户

wKiom1mx_yHQmLpKAABmhbLrwq8507.png-wh_50


其他:

导出用户的命令
第一步,先获取AD上所有的OU 命令:Get-ADOrganizationalUnit -Filter 'Name -like "*"'
第二部,根据OU获取用户 命令:
Get-ADuser -searchbase 'OU=IT,DC=dareway,DC=com' -filter 'name -Like "*" ' -Properties * | Export-Csv c:\sharepointinfo.csv -enconding utf8
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
name,SamAccountName,GivenName,Surname,DisplayName,Department,UserPrincipalName,City,Office,StreetAddress,State,PostalCode,Title,Company,OfficePhone,HomePhone,MobilePhone,emailaddress
-------------------------------------------------------------------------------------------------------------------------------------------------------
获取用户信息中所需要的字段:
Get-ADuser -searchbase 'OU=IT,DC=dareway,DC=com' -filter 'name -Like "*" ' -Properties name,SamAccountName,GivenName,Surname,DisplayName,Department,UserPrincipalName,City,Office,StreetAddress,State,PostalCode,Title,Company,OfficePhone,HomePhone,MobilePhone,emailaddress | Export-Csv c:\sharepointinfo.csv -enconding utf8
导入用户的命令
将CSV文件用记事本打开,并另存为Unicode编码
PS C:\Users\Administrator\Desktop> Import-Csv "e:\file.csv" | foreach-object {New-ADUser -Path "ou=IT,dc=dareway,dc=cn"
-Name $_.name -SamAccountName $_.SamAccountName -GivenName $_.GivenName -Surname $_.Surname -DisplayName $_.DisplayName
-Department $_.Department -UserPrincipalName $_.UserPrincipalName -City $_.City -Office $_.Office -StreetAddress $_.Stre
etAddress -State $_.State -PostalCode $_.PostalCode -Title $_.Title -Company $_.Company -OfficePhone $_.OfficePhone -Hom
ePhone $_.HomePhone -MobilePhone $_.MobilePhone -emailaddress $_.emailaddress -AccountPassword (ConvertTo-SecureString "
Dareway@2018" -AsPlainText -force) -enabled $true -ChangePasswordAtLogon $true -PasswordNeverExpires $false -Passthru}
----------------------------------------------------------------------------------------------------------------------------------------------------
随机生成初始密码
Import-Csv "e:\file.csv" | foreach-object {New-ADUser -Path "ou=IT,dc=dareway,dc=cn" -Name $_.name -SamAccountName $_.SamAccountName -GivenName $_.GivenName -Surname $_.Surname -DisplayName $_.DisplayName
-Department $_.Department -UserPrincipalName $_.UserPrincipalName -City $_.City -Office $_.Office -StreetAddress $_.Stre
etAddress -State $_.State -PostalCode $_.PostalCode -Title $_.Title -Company $_.Company -OfficePhone $_.OfficePhone -Hom
ePhone $_.HomePhone -MobilePhone $_.MobilePhone -emailaddress $_.emailaddress -AccountPassword (ConvertTo-SecureString $_.password -AsPlainText -force) -enabled $true -ChangePasswordAtLogon $False -PasswordNeverExpires $false -Passthru}

----------------------------------------------------------------------------------------------------------------------------------------------------
获取OU Beijing(包含子OU)下所有的user类型账户
get-user –OrganizationalUnit IT | where-object{$_.RecipientType –eq “User”}
批量启用用户
get-user –OrganizationalUnit IT | where-object{$_.RecipientType –eq “User”} | Enable-Mailbox –Database “Mailbox Database 0839106375” | get-mailbox | select name,windowsemailaddress,database