How do I change all students usernames in bulk please?

How do I change all students usernames in bulk please?

by Stressed Out -
Number of replies: 2

Hello,
I would like to know how to change all of the usernames just for the students (not staff) to their email address please? The usernames for students are currently set as the first letter of their forename, followed by their surname e.g. jsmith.  I would like to set all students usernames in bulk to their email address, before the @ sign. The students full email address has been added to Moodle previously.

Could anyone please let me know how to achieve this please?

I am using Moodle 3.9.2 (Build: 20200914)

Thank you

Average of ratings: -
In reply to Stressed Out

Re: How do I change all students usernames in bulk please?

by C Behan -
In reply to C Behan

Re: How do I change all students usernames in bulk please?

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

To expand on the previous reply:

Download a CSV file of students

  1. Go to Site administration ▸ Users ▸ Bulk user actions.
  2. Under New filter click Show more....
  3. Find Course role:
    1. Change any role to Student.
      Course role filter
    2. At the end of the list click Add filter.
  4. Under Users in list in Users select All filtered then click Add to selection.
    Users in list with filter
  5. At the bottom of the page in With selected users... select Download and click Go.
  6. In Export users as leave this as Comma separated values (.csv) and click Download and save the file.

Add the new username in the CSV file

  1. Open the downloaded file in a spreadsheet program, e.g. Excel.
  2. Change the first row of the username column to oldusername.
  3. Insert a new column, e.g. column B, and enter username in the first row. This column will contain the new username.
  4. In row 2 of this column enter the new username using a formula. If the email address is in column D in LibreOffice Calc this would be =LEFT(D2, SEARCH("@", D2) - 1), it may be the same in Excel.
    Spreadsheet with oldusername and username column
  5. Copy and paste this formula into the remaining rows.
  6. Save the file. This must be saved as in CSV format (not .xlsx, .ods, etc.).

Upload the updated CSV file

  1. Go to Site administrationUsersUpload users.
  2. Select the updated CSV file and click Upload users.
  3. On the Upload users preview page under Settings:
    1. change Upload type to Update existing users only,
    2. change Allow renames to Yes.
      "Settings" section showing "Upload type" and "Allow renames" fields
  4. Click Upload users.
  5. The Upload users results page should show the username change as expected.
I would recommend making this change with a small number of users first to test it works as expected, ideally try it on a test or staging site if available.
Average of ratings: Useful (5)