Im trying to write a script to fix the display names to an updated office. I've made a script that corrects the office and writes it back to AD (using Set-QADuser objectattribute o), but that didnt automatically update the display name in Ad OR DRA. Now i'm trying to get it to correct the cn and hopefully that will fix the displayed name. here is my script. This is my first PS script so if there is a better way to do it let me know!
$SNAPIN=’Quest.Activeroles.
ADD-PSSNAPIN $SNAPIN –erroraction SilentlyContinue
#Sets OU path variable
$OUPath = "Test OU/Users"
#Sets Export Path Variable
$ExportPath= "C:\Users.csv"
#Loads AD objects into $Result with DN,o,cn attribs, selects those attribs, and writes to CSV. Displays Results
$Result = Get-QADUser -SearchRoot $OUPath -sizelimit 0 -IncludedProperties dn,o,cn | select dn,o,cn | EXPORT-CSV -notype $ExportPath
#modifies the csv
(Import-Csv C:\Users.csv) | ForEach-Object{
if ($_.cn –contains 'office')
{
$_.cn = $cn -replace ('office','fixed office')
$_
}
elseif ($_.cn -contains 'office2')
{
$_.cn = cn -replace ('office2','fixed office2')
$_
}
else
{
$_
}
} | Export-Csv C:\Users_FIXED.csv -NoTypeInformation
#sends updated info to AD
Import-Csv C:\Users_FIXED.csv | ForEach {rename-QADUser -Identity $_.DN -newname '$_.cn'}