We have just gone to Office 365 tied in with ADFS. We want to be able to see people's departments automatically when we view their contact info in Office 365. We do not have any Department attributes currently assigned in AD. However, we basically have each department in it's own OU. Is there a way to automatically assign a department to each user based on the OU that they're in, so that if they move to a different department (and therefore OU) it will update on all levels?

  • 3
    Powershell scripts run on a nightly schedule should do the trick.
    – Hyppy
    Jan 21, 2015 at 17:19
  • What would be the syntax? Would it be Get-ADUser -filter * -SearchBase "ou=EXAMPLE,dc=MyDomain,dc=com" | Set-ADUser -Department "EXAMPLE" ? Jan 21, 2015 at 19:00
  • Sounds reasonable. Did it work?
    – Hyppy
    Jan 21, 2015 at 19:01
  • Yes, but I'm having trouble with nested OU's. Is there a certain syntax for those? Jan 21, 2015 at 22:26

1 Answer 1


As suggested in the comments, having a scheduled powershell script run would be the best course of action.

How you schedule is up to you, I would suggest some time late in the evening, so any changes you've made during the day will take place overnight.

Now the script... I think it would be prudent to have the script pull all the users from the OU and set their department name to something you've chosen, rather than setting it based on the OU name. My reasoning for this is that your OU names might not reflect the name a department would like to have displayed.

e.g The finance department may come to you and say please update our department to "Companyname Finance Team" and you're OU name is still "Finance". It would then be easier to edit one entry in script, rather than renaming your OU to something potentially long and horrible.


get-aduser -Filter * -SearchBase "ou=FINANCE,dc=iammred,dc=net" | Set-ADUser -Department Finance

Obviously replace the "ou=xxx" and "-Department xxx" with your OU and desired department name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .