Syncing Existing Office 365 Users to newly created AD Domain

At our MSP we often need to set up an Active Directory environment for a company that already has office 365. We then set up Azure Active Directory Connect to sync the credentials from the office back to AzureAD so they only have one password.

I added the script from Slash admin to my toolbox. below is copy of the script in case the blog goes away. but the original is bog post is https://www.slashadmin.co.uk/…

Some notes from the original blog 

Before running the script there are two things to note:

  1. User accounts that get created in the local AD will have the password set to “Password123..” but you can change this in the script before running it. You will have to let all users know this beforehand or manually update the passwords. This password will sync back to Office 365 as soon as you configure Azure AD Connect to maintain a permanent sync.
  2. By default the script will create all accounts in the default user container. You can override this by manually creating a new OU in the AD and updating the $usersContainer variable in the script.

you my also need to make the change below if you have more than 100 users

#Add users to local AD
Get-AzureADUser -All $True | Add-LocalADObject
#Add contacts to local AD
Get-AzureADContact -All $True | Add-LocalADObject
#Add groups to local AD
Get-AzureADGroup -All $True | Add-LocalADObject