Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, April 8, 2013 5:53 PM
I am trying to update/change the email addresses of users based on information in a csv file. I am also using the Quest Active Roles management modules. My code does not return any errors but it is not populating the email field either. I am sure it is something simple but I can't seem to find it. Any help would be appreciated.
#Gets a list of user accounts from Active Directory
$adobj=Get-QADUser -searchroot 'my.company.com/Somthing/BizUnit/Vicims' -SizeLimit 0 -includeallproperties
#list of EDSP accounts with email addresses and employeeID
$UserList=Import-Csv .\VictimList.csv
foreach ($user in $UserList) {
#compare the csv file to adobj for entries that match
where {$adobj.employeeID -eq $UserList.employeeID} |
#when there is a match set the mail attribute to what is listed in the PrimarySMTPAddress in the csv
Set-QADUser -Identity $user.employeeID -ObjectAttributes @{mail = $UserList.PrimarySMTPAddress}
}
All replies (1)
Monday, April 8, 2013 6:40 PM âś…Answered | 1 vote
So the problem with your code is that you are only working through 1 array. Your 'foreach' expands out the array from the csv but $adobj is still in an array format when you try and access the $adobj.employeeid property.
This should work provided that the employeeID property is accessible in your AD:
Import-Csv .\VictimList.csv |
foreach
{ Get-QADUser -LDAPFilter "(EmployeeID -eq $_.EmployeeID)" | Set-QADUser -ObjectAttributes @{mail = $UserList.PrimarySMTPAddress} }
<# or if employeeid matches a -identity parameter value #>
Import-Csv .\VictimList.csv |
foreach
{ Get-QADUser -identity $_.EmployeeID | Set-QADUser -ObjectAttributes @{mail = $UserList.PrimarySMTPAddress} }
If employeeID matches up with a value for identity then you're good to use the second one.
Hope that helps! Jason