PowerShell – Prevent Teams from showing in Outlook Global Address List

If you are one of the Microsoft Teams enthusiasts and started using Teams from its early stage, you have ended up with many similar or unintended email IDs in your Outlook GAL. For each Team, Office 365 creates its own group’s email ID and it used to make the email ID available in the GAL.

After some noise in the User Voice, Microsoft stop showing those email IDs in the GAL by default. But if you already have many group email IDs showing in your GAL that you want to hide, use the following code snippets:


List all Office 365 Groups & Delete Office 365 Groups

In the tenant using Modern Authentication and/or multi-factor authentication (MFA), connect to the Exchange Online PowerShell Module to work with groups.

  • Use IE/Edge (don’t skip), go to the Exchange admin center
  • Go to Hybrid > Click the second configure >
  • In the PowerShell window enter the following to connect. Details docs are in the reference links.

Connect-EXOPSSession -UserPrincipalName anupam.ranku@domain.com

To list all Office 365:


View all the properties of the group:

Get-UnifiedGroup -Identity "My Group Name" | Format-List

Note: ExternalDirectoryObjectId is same as other group Ids (e.g. Teams GUID).

Selected properties can be exported to excel file:

Get-UnifiedGroup | Select-Object -Property DisplayName, GroupType, ExternalDirectoryObjectId, PrimarySmtpAddress, Name | Export-Csv -Path .\ExportGroups.csv -NoTypeInformation

After manipulating the excel files, the same file can be used to delete/clean-up test/unwanted Groups:

Import-CSV .\ExportGroups.csv | Foreach-Object{
Write-Host "Deleting" $_.Name
Remove-UnifiedGroup -Identity $_.Name -confirm:$false

The above is a soft-delete of the groups and will be retained for another 30 days (for admin to restore). To reuse the same group internal name, those groups need to be permanently deleted. We will need to use AzureAD PowerShell Module for this. Run the following commands and sign-in again to see the list of deleted groups.

Import-Module AzureADPreview
#The list can be exported in a excel for curation.
Get-AzureADMSDeletedGroup | Select-Object -Property DisplayName, ID | Export-Csv -Path .\DeletedGroups.csv -NoTypeInformation

After modifying the export file, same can be used to permanently delete those groups.

Import-CSV .\DeletedGroups.csv | Foreach-Object{
Write-Host "Permanently deleting" $_.DisplayName
Remove-AzureADMSDeletedDirectoryObject -Id $_.ID

Issues: if you are getting the following error, you have missed the step highlighted above in red. Use IE/Edge.
You cannot start application Microsoft Exchange Online Powershell Module from this location because it is already installed from a different location.