I'm trying to update Active Directory users information using Office 365 information.
The first step was to retrieve all users I have on Office 365:
$Users = Get-msoluser | sort UserPrincipalName
Then I need to add a property called ADUser on each one (because my Active Directory isn't federated with Office 365, then... AD user is different that Office 365 user.)
I've tried something like this:
Your logic isn't quite correct. You are returning ALL AD users and then filtering to find a user, for every person in your Get-MSOLUser dump, which is going to take a long time. Take a look at this logic that searches for the AD User, gets the SamAccountName and then we return the UPN from $users (Get-MSOLUser) and add a property for SamAccountName from $AdUser (Get-ADUser):