I have a script that is currently working fine. It pulls information from a CSV and updates the attributes in AD if the column in the CSV doesn’t contain #. I would like to also clear any attributes in AD (using -CLEAR with Set-ADUser) if the corresponding column contains a #.
Here is and example of the working code. Sector is the column header in the CSV and rraSector is the custom attribute in AD that is updated if the Sector column in the CSV doesn’t contain #:
I’m thinking there should be another array to contain the name of any custom attributes that need to be cleared if they contain # in the CSV column. Ideally, I think, there could be an ‘else’ attached to the ‘if’, such as:
OR, perhaps, it would be better to cycle back through the CSV adding all fields that need to be cleared into $ClearAttrib after all values were updated in AD from $RRAAttrib?
I actually didn’t really get what your question is. What is your question?
How many custom attributes do you have in your AD? If you have an already working solution for one custom attribute why not uising the same solution for the other ones? I’d suspect you wouldn’t have hundrets of them, would you?
19 total attributes that are updating properly now. However, the source file contains # for columns that don’t have data in them from a different system. For example, someone could have been in a committe and now they are no longer in that committee. Then, that column in the CSV would have a #. I need to account for that and clear the AD attribute if that corresponding column in CSV has a # rather than just skip the # as I am already doing.
so, yes, currently my script is updating AD proprely but now I need to clear certain fields in AD based on whether there is a # or not in the CSV. That’s where I could use some guidance - best way to go about detecting the # in the CSV and then clearing the associated attribute in AD in the same script.
That works! Oddly, enough, though when testing and putting in the #, the rraSector data was pulled from the user record below the first one (I was just testing with the first 5 records in the CSV but only changing data for the first user record) so it was not clearing. I moved the $adUser variable assignment higher in my script, before the “If ($Sector)…” and that did the trick.