Updating a User attribute in the Enterprise

I was asked to update an attribute of the EmployeeNumber for each and every user in the Enterprise for a new Application that will be using the newly populated attribute for a Global Database application.

I had several examples that I could use for the job utilizing VbScript – but I wanted to use Powershell for the task.

It turned out to be a relatively easy task – using the Quest Active Directory Commandlets.

add-PSSnapin quest.activeroles.admanagement

 Connect-QADService -Service domain.com -Credential (Get-Credential)
 $infile = Import-Csv "c:\temp\file.csv"
 $logfile = "c:\temp\logfile.log"

 foreach ($line in $infile) {
        set-QADObject ($line.domain +"\" + $line.login) -ObjectAttributes `
        if ($? -eq $true){
        Write-output "Updated: $($line.domain)\$($line.login) with employeeNumber: `
            $($line.guid)" >>  $logfile
        } else {
        Write-output "Error in updating: $($line.domain)\$($line.login)" >> $logfile

 ##Get Results
 $results = foreach ($line in $infile) {
    get-QADObject ($line.domain +"\" + $line.login) -IncludedProperties `
       Name, employeeNumber | select Name, employeeNumber
 $results >> $logfile
 Disconnect-QADService -Service domain.com

A Quick explanation:

Add the Quest Snapin

Connect to the domain with acquired credentials

Import the CSV file that was formatted - domain,login,guid, and create a log file for results

Go through each line in the CSV – if successful log to the file and if not then report the error to the log file.

Go through the list of users again – retrieving only the Name and EmployeeNumber properties and pipe the results in the same log file.

The script to a longer to write than it did to run.

Hope you enjoyed the ride.