Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Bulk import AD users using powershell

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Save the text document as a csv file and pay attention to the coding format, otherwise it will be garbled after import.

Use the powellshell command to import

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. View established users

Other:

Export user's command

The first step is to get all the OU commands on AD: Get-ADOrganizationalUnit-Filter 'Name-like "*"

The second part is to obtain user commands according to 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 the required fields in the user information:

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

Import user's command

Open the CSV file in notepad and save it as Unicode encoding

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}

- -

Randomly generate initial passwords

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}

- -

Get all user accounts under OU Beijing (including sub-OU)

Get-user-OrganizationalUnit IT | where-object {$_ .RecipientType-eq "User"}

Batch enable users

Get-user-OrganizationalUnit IT | where-object {$_ .RecipientType-eq "User"} | Enable-Mailbox-Database "Mailbox Database 0839106375" | get-mailbox | select name,windowsemailaddress,database

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report