User ID creation in Active Directory

Hello All,

I’ve a script for creating user accounts in Active Directory and filling the necessary options including a description for each user account. The input file is in CSV and contains:

UserName,Surname,UserID,Email
SuperMan,FromPlanetEarth,SM10001,superman@earth.com
IronMan,FromMars,IM10002,ironman@earth.com

When the user gets created, the description field should get filled as ‘UserName’ + ‘Surname’ + ‘(Only the number in UserID)’ + L3. For example description would be, SuperMan FromPlanetEarth (10001) L3.

How can I write it into a variable to achieve this ? selecting only the number from UserID and putting it into a brackets ( ) is where I am failing.

Thanks in advance. A quick reply is much appreciated, I am running on tight schedules to complete a migration on 25th Apr 2022.

Regards,
Shyam.

If the UserID field always ends in a number this code which leverages regular expressions will pull out the numeric ending to the UserID.

$HereString = @"
UserName,Surname,UserID,Email
SuperMan,FromPlanetEarth,SM10001,superman@earth.com
IronMan,FromMars,IM10002,ironman@earth.com
"@

$Data = $HereString -split '\r?\n' | convertfrom-csv

foreach ($user in $Data) {
    if ($user.UserID -match '(\d+)$') {
        $matches[1]
    }
}

Thanks so much @riedyw, I will try it out right away.