使用powershell批量导入AD用户
admin
2023-03-16 11:01:21
0
  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








相关内容

热门资讯

今日重大消息“微乐家乡大贰辅助... 网上科普关于“微乐家乡大贰有没有挂”话题很是火热,小编也是针对微乐家乡大贰作*弊开挂的方法以及开挂对...
我来教教您“友乐广西麻将到底有... 您好:友乐广西麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款...
终于明白“花花生活圈开挂神器?... 网上科普关于“花花生活圈有没有挂”话题很是火热,小编也是针对花花生活圈作*弊开挂的方法以及开挂对应的...
终于了解“AAPOKER到底是... 有 亲,根据资深记者爆料AAPOKER是可以开挂的,确实有挂(咨询软件无...
终于明白“山西互动是不是有挂?... 网上科普关于“山西互动有没有挂”话题很是火热,小编也是针对山西互动作*弊开挂的方法以及开挂对应的知识...
【第一资讯】“推大石怎么装挂?... 有 亲,根据资深记者爆料推大石是可以开挂的,确实有挂(咨询软件无需打开直...
玩家分享攻略“秦乐陕西麻将开挂... 网上科普关于“秦乐陕西麻将有没有挂”话题很是火热,小编也是针对秦乐陕西麻将作*弊开挂的方法以及开挂对...
终于了解“新上游炸/金/花究竟... 网上科普关于“新上游炸/金/花有没有挂”话题很是火热,小编也是针对新上游炸/金/花作*弊开挂的方法以...
终于明白“趣友麻将究竟有挂吗?... 网上科普关于“趣友麻将有没有挂”话题很是火热,小编也是针对趣友麻将作*弊开挂的方法以及开挂对应的知识...
最新引进“至尊宝炸金花开挂器?... 家人们!今天小编来为大家解答至尊宝炸金花透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里...