Update AD users employeenumber based on csv file

I am currently using a workflow to update from field EmployeeID to EmployeeNumber.  Basically I am adding a letter in front of the employeeID to create employeeNumber.

Ex. employeeID "123456" become employeeNumber "A123456"

it working fine, but now I need to make sure they all have A+6 digits even if they have less than 4 digits in the Employee ID.

Ex. employeeID "1234"  should become employeeNumber "A001234" and not employeeNumber "A1234" 

  • The below script should take any length of employeeID, which is less than the required number of digits, and add a leading digit, before adding the prefix character.

    $Prefix = "A"
    $RequiredLength = 6
    $LeadingChar = 0
    $EmployeeID = "1234567"
    $EmployeeNumber = ""
    $CurrentLength = $EmployeeID.length
    If($CurrentLength -gt $RequiredLength)
        Return "Employee Identity longer than required length"
    ElseIf($CurrentLength -lt $RequiredLength)
        $LeadingZeroRequired = $RequiredLength - $CurrentLength
            $EmployeeID = [string]::Format("{0}{1}",$LeadingChar,$EmployeeID)
        } While ($LeadingZeroRequired -ne 0)
    $EmployeeNumber = [string]::Format("{0}{1}",$Prefix,$EmployeeID)

  • Thanks Stu for thw quick answer.

    I modify the workflow by editing the script in the updating rules on the source side

    and the result before comitting is the following:

    For all users with employeeID less than 6 digits or more it would modify the EmployeeNumer to display "Employee Identity longer than required length"

    I am thinking maybe there's a way to divide the workflow in 2, one for those with less than 6 digits in EmployeeId and one another one for 6 digits ?

  • Can you share the script you used in your Workflow?

    If its actually outputting "Employee Identity longer than required length" them it might be processing an entry there the existing length of the source attribute is longer than required. It would probably be best in that instance to just not update it.

    Also if you have are coying the value from Attribute1 (EmployeeNumber) and putting it into Attribute2 (EmployeeID), I'd validate both sides, IE:

    If the length of EmployeeNumber is 6 of less, but not null, copy across to EmployeeID adding leading character to make it 6 character, then prefix your A value.

    If the length of the EmployeeNumber is 7 or more, this is not valid (that I'm aware of), so don't bother updating the EmployeeID.

    If the length of employeeNumber is 0., dont update EmployeeID.

    Hope this help.

  • 1 - on the workflow source I use updating criteria so only if employeeID is present 

    2 - in updating rules, I specify the csv (generated by powershelll script) and modify the "employeenumber" on the domain

    3 - I am trying the PS script you previously posted

    Now If I run the workflow, it want to modify the accounts with the text "Employee Identity longer than required length" whatever the number of characters