none
Script needed to remove values from attributes RRS feed

  • Question

  • Trying to figure out how i can remove a value within a ad attribute, specifically the employeeid field in active directory...

    there are values like 12121212|23232323|3434343434|454545454

    how can i make a script to remove 2323232323 from everyone in AD, without harming the other values?

    • Moved by Bill_Stewart Monday, April 30, 2018 9:35 PM Unanswerable drive-by question
    Tuesday, February 27, 2018 4:42 PM

All replies

  • $employeeid = "12121212|23232323|3434343434|454545454"
    
    $substring = $employeeid.SubString(9,9)
    
    $employeeid.Replace("$substring","")


    Then just update the employee ID using the final $employeeid variable
    Tuesday, February 27, 2018 5:00 PM
  • help set-aduser -par clear

    \_(ツ)_/

    Tuesday, February 27, 2018 5:01 PM
  • There can be many variations, which I tried to account for in the following (not tested):

    $Users = Get-ADUser -Filter 'EmployeeID -Like "*2323232323*" ' -Properties EmployeeID
    ForEach ($User In $Users)
    {
        $NTName $User.sAMAccountName
        $ID = $User.employeeID.Replace("|2323232323", "").Replace("2323232323|", "").Replace("2323232323", "-")
        If ($ID -eq "-") {Set-ADUser -Identity $NTName -Clear EmployeeID}
        Else (Set-ADUser -Identity $NTName -EmployeeID $ID}
    }

    It helps to only retrieve users whose emploeeID value has the string to be removed. Assuming the pipe character is a delimiter, it may also need to be removed. But if there is only one value (no delimiter), you need to use -Clear, since you cannot assign an empty string to any attribute.

    Edit: I just noticed your ID value has "2323232323" (10 chars), but you want to remove "23232323" (8 chars). I assume a typo.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)




    Tuesday, February 27, 2018 6:15 PM