Create Microsoft 365 groups with the PowerShell in Exchange Online

MVP

 

Hi Microsoft 365 friends,

 

I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE

Set-Location C:\Temp
Clear-Host

 

#Get Credentials to connect
$Credential = Get-Credential
  
#Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
           -Credential $Credential -Authentication Basic -AllowRedirection
  
#Import the session
Import-PSSession $Session -AllowClobber

#Did it work?
Get-UnifiedGroup
 
#Create new Microsoft 365 Group
New-UnifiedGroup -DisplayName "Study Group" -Alias "0365-Study-Group" `
        -EmailAddresses "0365-Study-Group@tomwechsler.xyz" -AccessType Private

#An other Microsoft 365 Group (no space on the Alias Name)
New-UnifiedGroup –DisplayName "M365 Admins" -Alias "M365Admins" -AccessType Public

#Add a member
Add-UnifiedGroupLinks -Identity "M365 Admins" –LinkType Members –Links Tina.Jackson

#To list the Group Members
Get-UnifiedGroupLinks "M365 Admins" –LinkType Member

#To list the Group Owners
Get-UnifiedGroupLinks "M365 Admins" –LinkType Owner

#To add an additional Owner to the Group (this will not work!)
Add-UnifiedGroupLinks –Identity "M365 Admins" –LinkType Owner –Links tim.godin@tomwechsler.xyz

#First, we have to add Tim Godin as a member to the group
Add-UnifiedGroupLinks -Identity "M365 Admins" –LinkType Members –Links Tim.Godin

#Now we can add Tim Godin as an additional Owner to the Group
Add-UnifiedGroupLinks –Identity "M365 Admins" –LinkType Owner –Links tim.godin@tomwechsler.xyz

#To list the Group Owners
Get-UnifiedGroupLinks "M365 Admins" –LinkType Owner
 
Now you have used the PowerShell to create a Microsoft 365 Group! Congratulations!
 
#Remove the session (Do not forget to terminate the connection)
Remove-PSSession $Session
 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

3 Replies
Hi Tom, I see that you're using the old exchange powershell module. Why not use the v2 powershell module so you can use modern authentication with certificate authentication? That way you don't have to use basic authentication which will be deprecated by Microsoft?

Hi Ruud

You are absolutely right. In a next step I will switch to version 2. I have written this article with version 1 because I have received requests for it from several people.

Regards, Tom Wechsler

@RuudGijsbers 

Hi Tom

Then it makes sense. For the rest, well explained.

Regards,
Ruud