2.2 KiB
2.2 KiB
Bulk Student Email Assignment Script
Date: 2026-05-15 Project: Set-StudentEmail Status: resolved Tags: powershell, active-directory, email, students, bulk-update
Context
Student accounts in AD needed their mail attribute populated consistently so downstream systems had a reliable address per student. Jess wanted a script that walks the student OU and assigns every account an address derived from its AD username, with a safe preview mode.
Key Decisions
[SamAccountName]@<domain>format — the first version built addresses from firstname + surname, but this was switched the same day to the username. Username-based addresses are guaranteed unique and don't break on duplicate names, hyphenated/multi-part surnames, or name changes.- Lowercase and trimmed — avoids case-mismatch and stray whitespace from imported usernames.
- Don't overwrite by default — existing addresses are left alone unless
-Forceis passed, so manually-corrected addresses aren't clobbered. -WhatIfas the recommended first run — preview before touching AD.- OU and domain as parameters with defaults — defaults suit the school, but the script can be pointed elsewhere.
Technical Details
- Script:
Set-StudentEmail.ps1 - Parameters:
-OU(DN of student OU; default<redacted>),-Domain(default<redacted>),-Force,-WhatIf. - Requires the ActiveDirectory module and rights to modify user attributes in the target OU; run from a domain-joined machine or via
Enter-PSSessionto a DC.
Code Changes
Set-StudentEmail.ps1— new; OU scan, address build, skip/overwrite logic, WhatIf support. Later changed from name-based to username-based addresses.README.md— full usage docs and examples; updated for[username]@domainformat.
Open Questions / Next Steps
- Not scheduled — currently run manually. Could be folded into the enrolment/AD sync workflow so new students get addresses automatically.
- No log file output; consider writing a change log like
Staff-AD-email-disablerdoes if it becomes a scheduled task.
Artifacts
3d231b7— Change email format to [username]@domain420a964— Add Set-StudentEmail script- Repo: https://gitea.hideawaygaming.com.au/jessikitty/Set-StudentEmail