4 minutes reading time (846 words)

Create Microsoft Team and configure Office 365 group settings using PowerShell

How to create a Microsoft Team and change Office 365 unified group settings using PowerShell

In this example, we will create a Team and change the Microsoft 365 group settings so that it can be used as an email distribution group without showing under "Groups" in the Outlook client.

Before you begin

Install PowerShellGet and Teams PowerShell Module

Do you want PowerShellGet to install and import the NuGet Provider now? Yes

# Install PowerShellGet
Install-Module -Name PowerShellGet -Force -AllowClobber

# Install Teams PowerShell Module
Install-Module -Name MicrosoftTeams -Force -AllowClobber
 

Set PowerShell execution policy and import Teams module

Do you want to change the execution policy? Yes

# Set execution policy
Set-ExecutionPolicy RemoteSigned

# Import Teams PowerShell module 
Import-Module MicrosoftTeams 

Create Team using PowerShell New-Team

Sign into Teams online

# Sign into Teams online
Connect-MicrosoftTeams 

Create new private Team

# create new private team
New-Team -DisplayName  "London Sales" -Description "London Sales Team" -Visibility Private -MailNickName LondonSales -Owner itadmin@ctrlf.cloud
 

New-Team options

-Visibility Public Teams allow all users to join the group
Private Teams require an owner to approve the request to join
-MailNickName Email alias for the associated Office 365 group. MailNickName will be used as the PrimarySmtpAddress
-Owner The Team owner can add or remove people from the Team. If the owner is not specified, it is set to the admin user who created the Team

Add users to a Team using PowerShell Add-TeamUser

# Get Team ID
$Group = Get-Team -DisplayName "London Sales" | select GroupId
# Add user to Team
Add-TeamUser -GroupID $Group.GroupId -User bender@ctrlf.cloud 

Remove users from a Team using PowerShell Remove-TeamUser

# Get Team ID
$Group = Get-Team -DisplayName "London Sales" | select GroupId
# Remove user from Team
Remove-TeamUser -GroupID $Group.GroupId -User zoidberg@ctrlf.cloud
 

Get Team members using PowerShell Get-TeamUser

$Group = Get-Team -DisplayName "London Sales" | select GroupId
Get-TeamUser -GroupID $Group.GroupId  

Change Office 365 group settings using PowerShell

Next we need to change the Microsoft 365 group settings so that it will show in the global address list and can be used as an email distribution group without showing under "Groups" in the Outlook client.

Connect to Exchange online PowerShell

...

Install the new Exchange Online PowerShell V2 module - TechLabs

How to install the new Exchange Online PowerShell V2 (EXO V2) module. The new EXO V2 module allows you to connect to Microsoft 365 Services using MFA and includes new Exchange online PowerShell cmdlets.
# Connect to Exchange Online PowerShell 
Connect-ExchangeOnline -UserPrincipalName itadmin@ctrlf.cloud 

Get Office 365 group settings using PowerShell Get-UnifiedGroup

# get m365 group settings
Get-UnifiedGroup -Identity "London Sales" | fl

# get m365 group settings and output to file
Get-UnifiedGroup -Identity "London Sales" | fl | out-file -filepath "C:\temp\london-sales-team.txt"
 

Change Office 365 group settings using PowerShell Set-UnifiedGroup

In this example, we will change the Microsoft 365 group settings so that it can be used as an email distribution group without showing under "Groups" in the Outlook client.  

# change m365 group settings
Set-UnifiedGroup -Identity "Sales" -HiddenFromAddressListsEnabled:$false -HiddenFromExchangeClientsEnabled:$true -UnifiedGroupWelcomeMessageEnabled:$false -AutoSubscribeNewMembers
 

Office 365 unified group settings

-HiddenFromAddressListsEnabled:$false
Default setting is HiddenFromAddressListsEnabled : True
M365 group is visible in address lists
-HiddenFromExchangeClientsEnabled:$true
Default setting is HiddenFromExchangeClientsEnabled : True
M365 group is hidden in Outlook client
-UnifiedGroupWelcomeMessageEnabled:$false
Default setting is WelcomeMessageEnabled : False
Disable sending system welcome messages to users when they are added to the group
-AutoSubscribeNewMembers
Default setting is AutoSubscribeNewMembers : False
Members will receive copies of team emails in their inboxes. The M365 group is used as a distribution list.

Send copies of team emails and events to team members inboxes

When this option is ticked, the M365 group is used as a distribution list. This can be enabled using PowerShell Set-UnifiedGroup -AutoSubscribeNewMembers

Don't show team email address address in Outlook

When this option is unticked, the Team will show in the Outlook global address list. This can be configured using PowerShell Set-UnifiedGroup -HiddenFromAddressListsEnabled:$false 

Microsoft 365 Group shows in the Outlook global address list

Hide Office 365 group in Outlook

Microsoft 365 group does not show in Outlook client

This can be configured using PowerShell Set-UnifiedGroup -HiddenFromExchangeClientsEnabled:$true

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Saturday, 23 September 2023
You can help support this website by buying me a coffee!
Buy Me A Coffee