Hi guys,
I have a script which exports current user info from AD into a CSV file with saMAccountName, department, description, title, company and office.
This works great. I then can edit it and upload it back into AD with the following script:
$data=import-csv c:\aduserlist.csv
foreach ($_ in $data)
{
if ($_.sAMAccountName -ne ''){
$identity = $_.sAMAccountName
}
else {
$identity = ''
}
if ($_.company -ne ''){
$company = $_.company
}
else {
$company = ''
}
if ($_.department -ne ''){
$department = $_.department
}
else {
$department = ''
}
if ($_.description -ne ''){
$description = $_.description
}
else {
$description = ''
}
if ($_.title -ne ''){
$title = $_.title
}
else {
$title = ''
}
if ($_.office -ne ''){
$office = $_.office
}
else {
$office = ''
}
set-ADuser -identity $identity -company $company -department $department -description $description -title $title -office $office }
}
This works, any field I update, it updates in AD - BUT, any field that is blank it updates with other user info ( ie. If I leave Title blank, it will update it in AD with the last title entered in the CSV file. ) So if User1 title is listed as Manager in the CSV, and User2 does not have a title ( ie, blank cell ) it will give User2 the same Manager title, rather than just leaving it blank - which is what I want it to do.
So basically, I want to to realize that if a cell is blank, to leave it blank in AD/update it to be blank
Any help appreciated!
- Edited by kb123nz Tuesday, October 23, 2012 7:05 PM