FunctionsPublic/New-GraphGroup.ps1
function New-GraphGroup { param([psobject]$accessToken, [string]$groupName, [string]$mailNickname, [string]$visibility = "Public") # # Create new unified group # $sendBody = @{ "displayName"="$($groupName)"; "description"="$($groupName)"; "groupTypes"=@("Unified"); "mailEnabled"= $true; "mailNickname"="$($mailNickname)"; "securityEnabled"=$false; "visibility"=$visibility } | ConvertTo-Json $responseBody = Invoke-RestMethod ` -Uri "https://graph.microsoft.com/v1.0/groups" ` -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"} ` -Body $sendBody ` -ContentType "application/json" ` -Method POST $jsonResponse = $responseBody | ConvertTo-JSON $createdGroup = ConvertFrom-Json -InputObject $jsonResponse return $createdGroup } |