Jump to content

Recommended Posts

Posted

Our student users all have usernames (in AD, domain controllers are Server 2012 & 2008 R2) that conform to a naming system (a series of letters and numbers) - this was originally set up (years before I started) to give students some protection from random cyber bullying

 

we have O365 in a hybrid config with our on-prem Exchange. Most students had their mailboxes migrated to O365, to get this to work as we wanted it to, we had to tweak two attributes in AD - 'UserPrincipalName' & 'ProxyAddresses'

 

Note : I *think* we might have had to tweak one of those attributes because our domain/email address doesn't match our legacy local computer domain name

 

SLT have decided that they want all student usernames /O365 email addresses changing to be the actual students name ... and they impatient for this to be done.

 

I'm guessing that there will be powershell scripts / tools to enable me to do this but ... I'm mighty cautious... screwing up hundreds of AD accounts and by extension, hundreds of O365 accounts ... nightmare.

 

Anyone had to do similar? Any tips ? (other than DON'T DO IT!)

Posted

Having a dig around and some this looks *easy enough*... To get started at least!

 

I can run a PowerShell script to extract: SamAccountName, GivenName, Surname attributes of all users in an OU and store in a CSV file.

 

I can fiddle with the data to make a new CSV (accountChange.csv) that has columns SamAccountName, NewSamAccountname, NewUPN,

(SamAccountName is the identifier, NewSamAccountName is "GivenName" + "-" + " "Surname" & NewUPN is the same + "mydomain.com"

 

Then this script will change the attributes

 

*******************

# Import AD Module

Import-Module ActiveDirectory

 

# Import CSV into variable $userscsv

$users = Import-Csv -Path C:\Scripts\accountChange.csv

 

#Set OU

$DistName = "OU=Test users,OU=Establishments,DC=mydomain,DC=internal"

 

 

# Loop through CSV and update users if the exist in CVS file

 

foreach ($user in $users) {

#Search in specified OU and Update existing attributes

Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase $DistName |

Set-ADUser -SamAccountName $($user.NewSamAccountName) -UserPrincipalName $($user.NewUPN) -EmailAddress $($user.NewUPN)

}

*******************

 

This doesn't do any error checking (users with no listed givenname or surname, users with the same name etc) but what's really stuping me is changing the primary SMTP address in the proxyAddresses attribute...

 

NOTE : I am testing this on test accounts in a test OU!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...