The reason you need to first set an alias/mailnickname value is because of the default rules in AAD Connect. Without this property, the object will not be recognized as an Exchange recipient, and thus all Exchange related rules will be skipped. In turn, this means that in order to update any Exchange-related property via AAD Connect, you need to have mailnickname populated.
Why we need to set mailnickname for Hiding users from Global Address List (GAL)?

Dear experts,
I'm exploring the way to hide some disabled users from our GAL, we are using AAD Connect to sync our on-prem objects to Office Exchange online.
I was in the impression that we need to firstly set the value of mailnickname for that user before setting the msexchhidefromaddresslists=$true.
What is the relationship behind? I'm not really sure why mailnickname will affect the GAL.
Thanks a lot for your advice.
Exchange Online
3 answers
Sort by: Most helpful
-
Vasil Michev 119.7K Reputation points MVP Volunteer Moderator
2022-12-14T07:59:06.243+00:00 -
Amit Singh 5,306 Reputation points
2022-12-14T07:23:41.007+00:00 Please confirm whether the disabled mailbox can be returned with the following command:
Get-User -ResultSize unlimited | where {$_.UserAccountControl -eq 'AccountDisabled,NormalAccount' -and $_.RecipientType -eq 'UserMailbox'}
If it works, please run the following command to meet your requirement:
Get-User -ResultSize unlimited | where {$_.UserAccountControl -eq 'AccountDisabled,NormalAccount' -and $_.RecipientType -eq 'UserMailbox'} | Set-Mailbox -HiddenFromAddressListsEnabled $true
-
Yuki Sun-MSFT 41,376 Reputation points Moderator
2022-12-14T08:29:00.83+00:00 Hi @Eaven HUANG ,
I was in the impression that we need to firstly set the value of mailnickname for that user before setting the msexchhidefromaddresslists=$true.
Yes, it's true and below is an official article with some explanation for reference:
Changes to msExchangeHiddenFromAddressList attribute not updated against recipient object in Exchange Online
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.