export users from activedirectory

علی ذوالفقار
1401/01/17 11:18:42 (486)
Get-ADUser -Filter * -Properties * | Select-Object userprincipalname , samaccountname | export-csv -path c:\AllUsers.csv
use the file to add other fields , like phone as this :
username,phone
user1,123-456-7891
user2,123-456-9892
user3,123-456-9893

$file = import-csv c:\users\administrator\desktop\alluser1.csv
foreach ($data in $file)
{
$samaccount = $data.username
$phonenumber = $data.phone
set-aduser -identity $samaccount -HomePhone $phonenumber
}
or
import-csv c:\users\administrator\desktop\alluser1.csv |
    ForEach-Object{
        set-aduser -identity $_.username -HomePhone $_.phone
    }

Back