msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

New-MgGroup and mailEnabled

Open markwahl-msft opened this issue 4 years ago • 2 comments

In Graph beta, create group specifies that the request payload should have

Property Type Description
mailEnabled boolean Set to true for mail-enabled groups. Required.

Note this field is required, if I attempt to create a group and do not provide mailEnabled in the request, the request fails with

{"error":{"code":"Request_BadRequest","message":"A value is required for property 'mailEnabled' of resource 'Group'."

However, the cmdlet syntax for New-MgGroup in beta is that [-MailEnabled] is an optional parameter. Invoking New-MgGroup does not send mailEnabled: false and so the request fails.

In order to create a non-mail-enabled group, the workaround I see is to use additionalproperties, as in

$ht = @{}
$ht["mailEnabled"] = $false
New-MgGroup -DisplayName "s" -SecurityEnabled -AdditionalProperties $ht -MailNickname "s"

It would be preferable if

New-MgGroup -DisplayName "s" -SecurityEnabled

could be used to create a non-mail-enabled security group.

AB#10168

markwahl-msft avatar Jul 08 '21 23:07 markwahl-msft

@markwahl-msft, a quick work around is to the set -SecurityEnabled to false using -SecurityEnabled:$false. This sets the value of the switch to $false (not ideal).

New-MgGroup -DisplayName "s" -SecurityEnabled:$false -Debug

A complete fix will need to come from two places:

  1. Workload owners should annotate this property as required. This can be done by adding RequiredProperties capability annotation in the $metadata. We currently treat -SecurityEnabled as optional because that's what the default is if RequiredProperties isn't specified.
  2. AutoREST should serialize switch parameters that haven't been set to false. Alternatively, boolean properties should be generated as boolean parameters.

peombwa avatar Jul 16 '21 01:07 peombwa

Will be fixed by https://github.com/microsoftgraph/msgraph-metadata/issues/128.

peombwa avatar Mar 11 '22 00:03 peombwa

As a PowerShell user I would like to see parameters that "look like" switches be coded as [Switch]. Parameters coded as [Boolean] should be avoided unless the the $null state is also valid. API parameters that are "mandatory" are still fulfilled, with a value of $false when a switch parameter is not explicitly provided at the Command Line.

AspenForester avatar Nov 15 '22 17:11 AspenForester

The property will remain a [switch] as explained in https://github.com/Azure/autorest.powershell/issues/1040#issuecomment-1352442281.

Closing since the issue is being tracked in https://github.com/microsoftgraph/msgraph-metadata/issues/128.

peombwa avatar Jan 24 '23 22:01 peombwa