You have to run PS as an administrator.
Update AD User properties via CSV file in powershell
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
$USERS|Foreach{
Set-ADUSer -Identity $_.samaccountname -Replace @{employeeID=$empid; company=$company; title=$title; department=$department; division=$division; postofficebox=$pobox; l=$City}
}
but I am getting insufficient rights issue where as I am an enterprise admin.
Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
5 additional answers
Sort by: Most helpful
-
Zeeshan Qaiser Opel 41 Reputation points
2022-04-19T06:50:59.35+00:00 Got the script working without any errors but the values are not getting updated for division attribute.
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.samaccountnameForEach ($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}
}
} -
Андрей Михалевский 3,451 Reputation points
2022-04-19T07:12:35.573+00:00 Import-Module ActiveDirectory $USERS = Import-CSV c:\users.csv $USERS | foreach { $empid=$_.employeeid $company=$_.company $title=$_.title $department=$_.department $Division=$_.division $pobox=$_.pobox $city=$_.city Set-ADUSer -Identity $_.samaccountname -Replace @{employeeID=$empid; company=$company; title=$title; department=$department; division=$division; postofficebox=$pobox; l=$City} }
-
Zeeshan Qaiser Opel 41 Reputation points
2022-04-19T07:18:37.537+00:00 Got this error
Set-ADUSer : Insufficient access rights to perform the operation
At C:\Users\users\Desktop\UserUpdate.ps1:15 char:6- Set-ADUSer -Identity $_.samaccountname -Replace @{employeeID=$em ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (user:ADUser) [Set-ADUser], ADException
- FullyQualifiedErrorId : ActiveDirectoryServer:8344,Microsoft.ActiveDirectory.Management.Commands.SetADUser
-
Zeeshan Qaiser Opel 41 Reputation points
2022-04-20T03:22:24.873+00:00 Issue resolved. Script ran flawlessly. Thanks a lot for ur help.