使用powershell批量导入AD用户-成都快上网建站

使用powershell批量导入AD用户

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

    创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、成都做网站、虎林网络推广、微信小程序、虎林网络营销、虎林企业策划、虎林品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供虎林建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

    使用powershell批量导入AD用户

    使用powershell批量导入AD用户

  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.查看建立的用户

使用powershell批量导入AD用户

其他:

导出用户的命令
第一步,先获取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








网页标题:使用powershell批量导入AD用户
文章源于:http://kswjz.com/article/ieiesh.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流