AD user modify

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Biswajit Biswajit 2 years, 3 months ago.

  • Author
    Posts
  • #18212
    Profile photo of Biswajit
    Biswajit
    Participant

    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.

  • #18213
    Profile photo of Biswajit
    Biswajit
    Participant

    I have tried but that is replaced the entire value.

  • #18214
    Profile photo of Simon Wåhlin
    Simon Wåhlin
    Participant

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

    [Pre]
    $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
    }

  • #18215
    Profile photo of Biswajit
    Biswajit
    Participant

    Sure & thanks a ton. Will updat eyou shortly.

You must be logged in to reply to this topic.