New-MgGroup and mailEnabled
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.
@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:
- Workload owners should annotate this property as required. This can be done by adding RequiredProperties capability annotation in the $metadata. We currently treat
-SecurityEnabledas optional because that's what the default is ifRequiredPropertiesisn't specified. - AutoREST should serialize
switchparameters that haven't been set tofalse. Alternatively,booleanproperties should be generated asbooleanparameters.
Will be fixed by https://github.com/microsoftgraph/msgraph-metadata/issues/128.
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.
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.