温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用powershell批量导入AD用户

发布时间:2020-08-12 17:03:53 来源:网络 阅读:1409 作者:烟台山下 栏目:建站服务器
  1. 建立文本文档另存为csv文件,注意编码格式,否则导入后是乱码

    使用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








向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI