Update AD User properties via CSV file in powershell

Zeeshan Qaiser Opel 41 Reputation points
2022-04-19T04:39:56.68+00:00

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
0 comments No comments
{count} votes

5 additional answers

Sort by: Most helpful
  1. 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.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}
    }
    }

    0 comments No comments

  2. Андрей Михалевский 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}
    }
    
    0 comments No comments

  3. 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
    0 comments No comments

  4. 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.