Create Microsoft 365 groups with the PowerShell in Exchange Online

%3CLINGO-SUB%20id%3D%22lingo-sub-1920372%22%20slang%3D%22en-US%22%3ECreate%20Microsoft%20365%20groups%20with%20the%20PowerShell%20in%20Exchange%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1920372%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Microsoft%20365%20friends%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20used%20the%20PowerShell%20ISE%20for%20this%20configuration.%20But%20you%20are%20also%20very%20welcome%20to%20use%20Visual%20Studio%20Code%2C%20just%20as%20you%20wish.%26nbsp%3BPlease%20start%20with%20the%20following%20steps%20to%20begin%20the%20deployment%20(the%20Hashtags%20are%20comments)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23The%20first%20two%20lines%20have%20nothing%20to%20do%20with%20the%20configuration%2C%20but%20make%20some%20space%20below%20in%20the%20blue%20part%20of%20the%20ISE%3C%2FP%3E%3CP%3E%3CSTRONG%3ESet-Location%20C%3A%5CTemp%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EClear-Host%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23Get%26nbsp%3BCredentials%26nbsp%3Bto%26nbsp%3Bconnect%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24Credential%26nbsp%3B%3D%26nbsp%3BGet-Credential%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23Create%26nbsp%3Bthe%26nbsp%3Bsession%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24Session%26nbsp%3B%3D%26nbsp%3BNew-PSSession%26nbsp%3B-ConfigurationName%26nbsp%3BMicrosoft.Exchange%26nbsp%3B-ConnectionUri%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Foutlook.office365.com%2Fpowershell-liveid%2F%26nbsp%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Foutlook.office365.com%2Fpowershell-liveid%2F%26nbsp%3B%3C%2FA%3E%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B-Credential%26nbsp%3B%24Credential%26nbsp%3B-Authentication%26nbsp%3BBasic%26nbsp%3B-AllowRedirection%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23Import%26nbsp%3Bthe%26nbsp%3Bsession%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EImport-PSSession%26nbsp%3B%24Session%26nbsp%3B-AllowClobber%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Did%26nbsp%3Bit%26nbsp%3Bwork%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-UnifiedGroup%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23Create%26nbsp%3Bnew%26nbsp%3BMicrosoft%26nbsp%3B365%26nbsp%3BGroup%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3ENew-UnifiedGroup%26nbsp%3B-DisplayName%26nbsp%3B%22Study%26nbsp%3BGroup%22%26nbsp%3B-Alias%26nbsp%3B%220365-Study-Group%22%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B-EmailAddresses%26nbsp%3B%220365-Study-Group%40tomwechsler.xyz%22%26nbsp%3B-AccessType%26nbsp%3BPrivate%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23An%26nbsp%3Bother%26nbsp%3BMicrosoft%26nbsp%3B365%26nbsp%3BGroup%26nbsp%3B(no%26nbsp%3Bspace%26nbsp%3Bon%26nbsp%3Bthe%26nbsp%3BAlias%26nbsp%3BName)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3ENew-UnifiedGroup%26nbsp%3B%E2%80%93DisplayName%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B-Alias%26nbsp%3B%22M365Admins%22%26nbsp%3B-AccessType%26nbsp%3BPublic%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Add%26nbsp%3Ba%26nbsp%3Bmember%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EAdd-UnifiedGroupLinks%26nbsp%3B-Identity%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B%E2%80%93LinkType%26nbsp%3BMembers%26nbsp%3B%E2%80%93Links%26nbsp%3BTina.Jackson%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Blist%26nbsp%3Bthe%26nbsp%3BGroup%26nbsp%3BMembers%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-UnifiedGroupLinks%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B%E2%80%93LinkType%26nbsp%3BMember%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Blist%26nbsp%3Bthe%26nbsp%3BGroup%26nbsp%3BOwners%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-UnifiedGroupLinks%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B%E2%80%93LinkType%26nbsp%3BOwner%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Badd%26nbsp%3Ban%26nbsp%3Badditional%26nbsp%3BOwner%26nbsp%3Bto%26nbsp%3Bthe%26nbsp%3BGroup%26nbsp%3B(this%26nbsp%3Bwill%26nbsp%3Bnot%26nbsp%3Bwork!)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EAdd-UnifiedGroupLinks%26nbsp%3B%E2%80%93Identity%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B%E2%80%93LinkType%26nbsp%3BOwner%26nbsp%3B%E2%80%93Links%26nbsp%3Btim.godin%40tomwechsler.xyz%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23First%2C%26nbsp%3Bwe%26nbsp%3Bhave%26nbsp%3Bto%26nbsp%3Badd%26nbsp%3BTim%26nbsp%3BGodin%26nbsp%3Bas%26nbsp%3Ba%26nbsp%3Bmember%26nbsp%3Bto%26nbsp%3Bthe%26nbsp%3Bgroup%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EAdd-UnifiedGroupLinks%26nbsp%3B-Identity%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B%E2%80%93LinkType%26nbsp%3BMembers%26nbsp%3B%E2%80%93Links%26nbsp%3BTim.Godin%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Now%26nbsp%3Bwe%26nbsp%3Bcan%26nbsp%3Badd%26nbsp%3BTim%26nbsp%3BGodin%26nbsp%3Bas%26nbsp%3Ban%26nbsp%3Badditional%26nbsp%3BOwner%26nbsp%3Bto%26nbsp%3Bthe%26nbsp%3BGroup%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EAdd-UnifiedGroupLinks%26nbsp%3B%E2%80%93Identity%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B%E2%80%93LinkType%26nbsp%3BOwner%26nbsp%3B%E2%80%93Links%26nbsp%3Btim.godin%40tomwechsler.xyz%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Blist%26nbsp%3Bthe%26nbsp%3BGroup%26nbsp%3BOwners%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-UnifiedGroupLinks%26nbsp%3B%22M365%26nbsp%3BAdmins%22%26nbsp%3B%E2%80%93LinkType%26nbsp%3BOwner%3C%2FSTRONG%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3ENow%20you%20have%20used%20the%20PowerShell%20to%20create%20a%20Microsoft%20365%20Group!%20Congratulations!%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23Remove%26nbsp%3Bthe%26nbsp%3Bsession%20(Do%20not%20forget%20to%20terminate%20the%20connection)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3ERemove-PSSession%26nbsp%3B%24Session%3C%2FSTRONG%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CP%3EI%20hope%20this%20article%20was%20useful.%20Best%20regards%2C%20Tom%20Wechsler%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EP.S.%26nbsp%3BAll%20scripts%20(%23PowerShell%2C%20Azure%20CLI%2C%20%23Terraform%2C%20%23ARM)%20that%20I%20use%20can%20be%20found%20on%20github!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftomwechsler%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftomwechsler%3C%2FA%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1920372%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1920676%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20Microsoft%20365%20groups%20with%20the%20PowerShell%20in%20Exchange%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1920676%22%20slang%3D%22en-US%22%3EHi%20Tom%2C%20I%20see%20that%20you're%20using%20the%20old%20exchange%20powershell%20module.%20Why%20not%20use%20the%20v2%20powershell%20module%20so%20you%20can%20use%20modern%20authentication%20with%20certificate%20authentication%3F%20That%20way%20you%20don't%20have%20to%20use%20basic%20authentication%20which%20will%20be%20deprecated%20by%20Microsoft%3F%3C%2FLINGO-BODY%3E
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