Author Posts

August 20, 2014 at 8:56 pm

I have 2000 Users. Need to modify the Lastname & Displayname. Both the attributes have the "service" keyword & that need to be replaced with "sales" keyword from both the attributes.
I dont want to put completely new value. Just need to replace the a word form them.

August 20, 2014 at 9:23 pm

I have tried but that is replaced the entire value.

August 20, 2014 at 11:09 pm

Try this, just remember to change $OU and $Filter.

$Filter = 'DisplayName -Like "*service*" -and Surname -Like "*service*"'
$OU = 'OU=MyOrg,DC=simonw,DC=se'

Get-ADUser -Filter $Filter -SearchBase $OU -Properties DisplayName | Foreach-Object {
$NewDisplayName = $_.DisplayName -replace 'service', 'sales'
$NewSurName = $_.Surname -replace 'service', 'sales'
Set-ADUser -Identity $_ -DisplayName $NewDisplayName -Surname $NewSurname

August 20, 2014 at 11:32 pm

Sure & thanks a ton. Will updat eyou shortly.