@@ -36,14 +36,12 @@ function Invoke-AddGroup {
3636 if ($GroupObject.groupType -eq ' m365' ) {
3737 $BodyParams | Add-Member - NotePropertyName ' groupTypes' - NotePropertyValue @ (' Unified' , ' DynamicMembership' )
3838 $BodyParams.mailEnabled = $true
39- }
40- else {
39+ } else {
4140 $BodyParams | Add-Member - NotePropertyName ' groupTypes' - NotePropertyValue @ (' DynamicMembership' )
4241 }
4342 # Skip adding static members if we're using dynamic membership
4443 $SkipStaticMembers = $true
45- }
46- elseif ($GroupObject.groupType -eq ' m365' ) {
44+ } elseif ($GroupObject.groupType -eq ' m365' ) {
4745 $BodyParams | Add-Member - NotePropertyName ' groupTypes' - NotePropertyValue @ (' Unified' )
4846 $BodyParams.mailEnabled = $true
4947 }
@@ -56,17 +54,15 @@ function Invoke-AddGroup {
5654 $BodyParams .
' [email protected] ' = @ (
$BodyParams .
' [email protected] ' )
5755 }
5856 $GraphRequest = New-GraphPostRequest - uri ' https://graph.microsoft.com/beta/groups' - tenantid $tenant - type POST - body (ConvertTo-Json - InputObject $BodyParams - Depth 10 ) - Verbose
59- }
60- else {
57+ } else {
6158 if ($GroupObject.groupType -eq ' dynamicDistribution' ) {
6259 $ExoParams = @ {
6360 Name = $GroupObject.displayName
6461 RecipientFilter = $GroupObject.membershipRules
6562 PrimarySmtpAddress = $Email
6663 }
6764 $GraphRequest = New-ExoRequest - tenantid $tenant - cmdlet ' New-DynamicDistributionGroup' - cmdParams $ExoParams
68- }
69- else {
65+ } else {
7066 $ExoParams = @ {
7167 Name = $GroupObject.displayName
7268 Alias = $GroupObject.username
@@ -87,19 +83,18 @@ function Invoke-AddGroup {
8783
8884 " Successfully created group $ ( $GroupObject.displayName ) for $ ( $tenant ) "
8985 Write-LogMessage - headers $Request.Headers - API $APIName - tenant $tenant - message " Created group $ ( $GroupObject.displayName ) with id $ ( $GraphRequest.id ) " - Sev Info
90-
91- }
92- catch {
86+ $StatusCode = [HttpStatusCode ]::OK
87+ } catch {
9388 $ErrorMessage = Get-CippException - Exception $_
9489 Write-LogMessage - headers $Request.Headers - API $APIName - tenant $tenant - message " Group creation API failed. $ ( $ErrorMessage.NormalizedError ) " - Sev Error - LogData $ErrorMessage
9590 " Failed to create group. $ ( $GroupObject.displayName ) for $ ( $tenant ) $ ( $ErrorMessage.NormalizedError ) "
91+ $StatusCode = [HttpStatusCode ]::InternalServerError
9692 }
9793 }
98- $ResponseBody = [pscustomobject ]@ {' Results' = @ ($Results ) }
9994
10095 # Associate values to output bindings by calling 'Push-OutputBinding'.
10196 Push-OutputBinding - Name Response - Value ([HttpResponseContext ]@ {
102- StatusCode = [ HttpStatusCode ]::OK
103- Body = $ResponseBody
97+ StatusCode = $StatusCode
98+ Body = @ { ' Results ' = @ ( $Results ) }
10499 })
105100}
0 commit comments