Update AD Users
-
Wednesday, January 30, 2013 5:43 PM
Hi,
I'm trying to update users in active directory from csv file with several values,
but some of that users didn't update because one of the values are empty.
Example
as csv file contains user data in the format (mobile value did not set):
samAccountName;givenName;sn;telephoneNumber;Pager;ipPhone;facsimileTelephoneNumber;mobile;physicalDeliveryOfficeName;department;description
jondoe;jon;doe;+xxxxxxxx;xxxx;+xxxxxxxxxxx;+xxxxxxxxxxx;;place;IT department;IT officerI'm using following code to update users:
Import-Module ActiveDirectory
$users = Import-Csv -Path c:\ADMIN\Users.csv -delimiter ";"
foreach ($user in $users) {
Set-ADUser -Identity $($user.SamAccountName) -Replace @{telephoneNumber = $($user.telephoneNumber); pager = $($user.Pager); ipPhone = $($user.ipPhone); facsimileTelephoneNumber = $($user.facsimileTelephoneNumber); mobile = $($user.mobile); physicalDeliveryOfficeName = $($user.physicalDeliveryOfficeName); department = $($user.department); description = $($user.description)}
}Can someone help me how to update users that doesn't have all values in csv file?
Much appreciated,
Nenad
All Replies
-
Wednesday, January 30, 2013 6:22 PMModerator
You cannot assign a blank string or null to any attributes in AD. In fact, if an attribute does not have a value, it technically is not even saved in AD; it is missing (to save space). You need to test for blank values and not assign a value if the value is null in the csv. Or, if a blank in the csv means that any existing value is to be removed, then you need to use code that clears the attribute (the -Clear parameter).
Richard Mueller - MVP Directory Services
- Marked As Answer by Bartek BielawskiModerator Monday, April 08, 2013 10:46 AM

