Scenario: You need to pull in additional AD properties for users with Exchange Online mailboxes that are only available when running the Get-ADUser command because they are not included in the AD Sync to Microsoft Online/Azure.
Scriptlet:
Declare Variables:
$mbx = Get-mailbox -resultsize unlimited
$ADUserData = @()
$c=0 #Just for a counter
Run the Loop:
$mbx | Where WindowsLiveID -ne “” | Sort | %{
$c++ #Increase the Counter
$upn = $_.windowsliveid #Create the UPN based off windowsliveid
$f = “Userprincipalname -eq ‘$upn'” #Create a Filter for get-aduser
“$c – $f ” #Display on PS Screen
$ADuserData += get-aduser -filter $f -properties * #Fill in $userData with Get-Aduser Data
}