Answered by:
Append Names to DisplayName with Powershell

Question
-
HI.
I need to append FirstName and SurName to the existing DisplayName in AD.
All Admin accounts, which start with SVC (so Svc6655 for example) need to be changed to show
SVC6655 - FirstName SurName
Thanks in advance
Monday, October 7, 2019 2:56 PM
Answers
-
Hi OP, use below script block, I have done small modification in the above command
Get-ADuser -filter 'samAccountName -like "SVC*"' -Properties * | ForEach {$_| Set-AdUser -DisplayName "$($_.samAccountName) - $($_.GivenName) $($_.Surname)" }
- Marked as answer by ianlloyd100 Wednesday, October 9, 2019 12:22 PM
Wednesday, October 9, 2019 10:42 AM -
This should be a new question as this one is answered. Just add it to the filter
Get-ADuser -filter 'samAccountName -like "SVC*" -and enabled -eq $true'
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
- Marked as answer by ianlloyd100 Thursday, October 17, 2019 7:17 AM
Wednesday, October 16, 2019 12:30 PM
All replies
-
Get-ADuser -filter 'samAccountName -like "SVC*"' | ForEach {
Something like that should work, you can remove the -WhatIf param if you are satisfied with the results
Set-AdUser -DisplayName "$($_.samAccountName) - FirstName SurName" -WhatIf }
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
- Edited by clayman2 Monday, October 7, 2019 3:41 PM added loop
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Tuesday, October 8, 2019 7:56 AM
Monday, October 7, 2019 3:38 PM -
Hi Clayman2.
Thanks for the quick response, and the code.
I am getting a request for the following parameters:-
Identity
Tuesday, October 8, 2019 9:36 AM -
Hi OP, use below script block, I have done small modification in the above command
Get-ADuser -filter 'samAccountName -like "SVC*"' -Properties * | ForEach {$_| Set-AdUser -DisplayName "$($_.samAccountName) - $($_.GivenName) $($_.Surname)" }
- Marked as answer by ianlloyd100 Wednesday, October 9, 2019 12:22 PM
Wednesday, October 9, 2019 10:42 AM -
Thats fantastic!.. Works perfectly!!..
Cudos to you
Thanks..
Wednesday, October 9, 2019 12:25 PM -
As a final spanner,
I now want to only look at accounts which are Enabled, and disregard disabled accounts...
Can I filter for 'enabled -eq $true' and if so where should I put it?
Thanks again...
Wednesday, October 16, 2019 9:53 AM -
This should be a new question as this one is answered. Just add it to the filter
Get-ADuser -filter 'samAccountName -like "SVC*" -and enabled -eq $true'
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''
- Marked as answer by ianlloyd100 Thursday, October 17, 2019 7:17 AM
Wednesday, October 16, 2019 12:30 PM