Hi Mike @mike-rodrick
I have one OU named "contacts" in this OU I have alot objects in type = contact, and i need to change display name.
Example:
First name: Mark
Last name: Donahu
Disply name: Donahu Mike (ITPRO)
I need to change the word in brackets on (NYYA), could you please help me, what comand i can use to make changes on whole OU=Contacts.
-
How to change DisplayName on AD object - CONTACT using PSH
-
Is the text inside the parenthesis the same for all contacts? If so, you could use something like this
$contacts = get-adobject -SearchBase "OU=contacts,DC=itprotvdemo,DC=com" -filter {objectclass -eq 'contact'} -Properties displayname foreach ($contact in $contacts){ $oldName = $contact.DisplayName $newName = $oldname.Replace("(ITPRO)","(NYYA)") Set-ADObject -Identity $contact -DisplayName $newName }
If the text inside the parenthesis is not the same for each contact, we will need to add some regular expressions.
Hope this helps,
-
Thank you for your help Mike, your script work perfect,
also, using your script I add some modifications to rename ADObject in AD
$contacts = get-adobject -SearchBase "OU=contacts,DC=ITPRO,DC=TV" -filter {objectclass -eq 'contact'} foreach ($contact in $contacts){ $oldName = $contact.Name $newName = $oldname.Replace("(ITPRO)","(WoPE)") Rename-ADObject -Identity $contact -NewName $newName } $contacts = get-adobject -SearchBase "OU=contacts,DC=ITPRO,DC=TV" -filter {objectclass -eq 'contact'} foreach ($contact in $contacts){ $oldName = $contact.Name $newName = $oldname.Replace("(ITPRO)","(WoPE)") Set-ADObject -Identity $contact -DisplayName $newName }
-
You're welcome, glad I could help!