About Me

My photo
HANUMANGARH, RAJASTHAN, India

Tuesday 20 December 2022

Update User properties in Active Directory from CSV

 

  1. Import-Module ActiveDirectory
  2. $USERS = Import-CSV c:\users.csv
  3. $USERS | foreach {
  4. $empid=$_.employeeid
  5. $company=$_.company
  6. $title=$_.title
  7. $department=$_.department
  8. $Division=$_.division
  9. $pobox=$_.pobox
  10. $city=$_.city
  11. Set-ADUSer -Identity $_.samaccountname -Replace @{employeeID=$empid; company=$company; title=$title; department=$department; division=$division; postofficebox=$pobox; l=$City}
  12. }


=====================================================================================================

Import-Module ActiveDirectory

$USERS = Import-CSV c:\users.csv

$empid=$USERS.employeeid
$company=$USERS.company
$title=$USERS.title
$department=$USERS.department
$Division=$USERS.division
$pobox=$USERS.pobox
$city=$USERS.city
$acc=$USERS.samaccountname

ForEach ($user in $USERS) {
Get-ADUser -Filter "samaccountname -eq '$Acc'" | Foreach {
Set-ADUser $ -Replace @{title = $title}
Set-ADUser $
 -Replace @{company = $company}
Set-ADUser $ -Replace @{department = $department}
Set-ADUser $
 -Add @{division = $division}
Set-ADUser $ -Replace @{postOfficeBox = $pobox}
Set-ADUser $
 -Replace @{l = $city}
Set-ADUser $_ -Replace @{employeeid = $empid}
}
}

No comments:

Post a Comment

Export contact from Justdial

  Extract Data From JustDial using Selenium Let us see how to extract data from Justdial using Selenium and Python. Justdial is a company th...