question

BenH-2229 avatar image
0 Votes"
BenH-2229 asked RichMatheisen-8856 answered

AD-Remove character from displayName Attribute in AD

Hello,

We currently use below to add 1 to any accounts' displayName attribute that are in a quarantine OU waiting to be deleted. It is part of a larger script.

Get-ADUser -SearchBase “OU=Quarantined,OU=Accounts,DC=Contoso,DC=com” -Filter { displayName -notlike "1"} -Properties displayname |

         

ForEach-Object {Set-ADObject -Identity $.distinguishedName -Replace @{displayName="$("1" + $.displayname)"}}

For some users who do return I have devised a script to enable various areas but I cannot seem to remove 1 from the displayName attribute if it exists. Any help would be appreciated.

windows-server-powershellwindows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Try this:

 Get-ADUser -SearchBase "OU=Quarantined,OU=Accounts,DC=Contoso,DC=com" -Filter { displayName -like "1*"} -Properties displayname |
     ForEach-Object {
         $d = $_.displayName -replace "^1", ""
         Set-ADObject -Identity $_.distinguishedName -Replace @{displayName="$d"}
     }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.