Microsoft 365 Group and Microsoft Graph

Creating a New Microsoft 365 Group with the Microsoft PowerShell Graph SDK

  1. Connect-ExchangeOnline
  2. Connect-IPPSSession
  3. Get-Label | ? {$_.ContentType -eq "Site, UnifiedGroup"} | ft DisplayName, ImmutableId
  4.  
  5. DisplayName ImmutableId
  6. ----------- -----------
  7. Non-business use a49e1277-93db-4a2f-8105-43c5196b4fef
  8. General Access e42fd42e-7240-4df0-9d8f-d14658bcf7ce
  9. Guest Access c29e68f9-bc4f-413b-a741-6db8e38ad1c6
  10. Limited Access d6cfd185-f31c-4508-ae40-229ff18a9919
  11. Confidential Access c99e52c6-f5ff-4050-9313-ca6a3a35710f
  12.  
  13. Connect-MgGraph -Scopes Group.ReadWrite.All, GroupMember.ReadWrite.All
  14. $SensitivityLabelId = "d6cfd185-f31c-4508-ae40-229ff18a9919"
  15. $NewGroupParams = @{
  16. "displayName" = "Microsoft Graph PowerShell SDK"
  17. "mailNickname"= "Microsoft.Graph.PowerShell.SDK"
  18. "description" = "People who like to discuss how to use the Microsoft Graph PowerShell SDK"
  19. "owners@odata.bind" = @(
  20. "https://graph.microsoft.com/v1.0/me"
  21. )
  22. "groupTypes" = @(
  23. "Unified"
  24. )
  25. "mailEnabled" = "true"
  26. "securityEnabled" = "true"
  27. "assignedLabels" = @(
  28. @{"LabelId"=$SensitivityLabelId}
  29. )
  30. }
  31. $Group = New-MgGroup -BodyParameter $NewGroupParams
  32.  
  33. $Uri= "https://graph.microsoft.com/v1.0/groups"
  34. $Group = Invoke-MgGraphRequest -Method Post -Uri $Uri -Body $NewGroupParams
  35.  
  36.  
  37. $NewTeamParams = @{
  38. "template@odata.bind"="https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
  39. "group@odata.bind"="https://graph.microsoft.com/v1.0/groups('$($Group.Id)')"
  40. }
  41. New-MgTeam -BodyParameter $NewTeamParams
  42.  
  43. $NewTeamParams = @{
  44. "template@odata.bind"="https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
  45. "group@odata.bind"="https://graph.microsoft.com/v1.0/groups('a771ae9d-6a93-4ccb-bbd0-dcfa55138f2f')"
  46. }
  47. $NewTeamParams = $NewTeamParams | Convertto-Json
  48. $Uri = "https://graph.microsoft.com/v1.0/teams"
  49. Invoke-MgGraphRequest -Uri $Uri -Method Post -Body $NewTeamParams