Skip to content

New-MgGroup with -BodyParameter drops parameters #3308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
archoversight opened this issue May 5, 2025 · 7 comments
Closed

New-MgGroup with -BodyParameter drops parameters #3308

archoversight opened this issue May 5, 2025 · 7 comments
Labels
type:bug A broken experience

Comments

@archoversight
Copy link

archoversight commented May 5, 2025

Describe the bug

I am trying to pass a dictionary (or hash map or whatever it is called in Powershell) to New-MgGroup with the body parameters to create the group. But it is failing.

Expected behavior

New group is created

How to reproduce

$GroupOptions = @{
  DisplayName     = "RandomTestGroup"
  Description     = "This is a random group"
  MailEnabled     = $false
  MailNickname    = -join ((48..57) + (97..122) | Get-Random -Count 32 | % {[char]$_})
  SecurityEnabled = $true
}
New-MgGroup -BodyParameter $GroupOptions -Debug

It seems to have completely dropped everything but mailEnabled and securityEnabled.

SDK Version

2.27.0

Latest version known to work for scenario above?

2.25.0

Known Workarounds

None

Debug output

Click to expand log
DEBUG: [CmdletBeginProcessing]: - New-MgGroup begin processing with parameterSet 'Create'.
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'InteractiveBrowser', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph PowerShell'.
DEBUG: [Authentication]: - Scopes: [Directory.ReadWrite.All, Group.ReadWrite.All, GroupMember.ReadWrite.All, openid, profile, User.ReadWrite.All, email].

Confirm
Are you sure you want to perform this action?
Performing the operation "New-MgGroup_Create" on target "Call remote 'POST /groups' operation".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
POST

Absolute Uri:
https://graph.microsoft.us/v1.0/groups

Headers:
FeatureFlag                   : 00000003
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Macintosh; Darwin 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:39 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6020; en-US),PowerShell/7.5.1
SdkVersion                    : graph-powershell/2.27.0
client-request-id             : a9d10562-5483-436c-a0ae-7ea651d095aa
Accept-Encoding               : gzip,deflate,b

Body:
{
  "mailEnabled": false,
  "securityEnabled": true
}


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Cache-Control                 : no-cache
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : a784386f-f47e-42c5-8985-7130c72abf33
client-request-id             : a9d10562-5483-436c-a0ae-7ea651d095aa
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"USGov Texas","Slice":"E","Ring":"4","ScaleUnit":"000","RoleInstance":"SN5NEPF0000319E"}}
Date                          : Mon, 05 May 2025 05:15:08 GM

Body:
{
  "error": {
    "code": "Request_BadRequest",
    "message": "A value is required for property 'displayName' of resource 'Group'.",
    "innerError": {
      "date": "2025-05-05T05:15:09",
      "request-id": "a784386f-f47e-42c5-8985-7130c72abf33",
      "client-request-id": "a9d10562-5483-436c-a0ae-7ea651d095aa"
    }
  }
}


New-MgGroup_Create: A value is required for property 'displayName' of resource 'Group'.

Status: 400 (BadRequest)
ErrorCode: Request_BadRequest
Date: 2025-05-05T05:15:09

Headers:
Cache-Control                 : no-cache
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : a784386f-f47e-42c5-8985-7130c72abf33
client-request-id             : a9d10562-5483-436c-a0ae-7ea651d095aa
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"USGov Texas","Slice":"E","Ring":"4","ScaleUnit":"000","RoleInstance":"SN5NEPF0000319E"}}
Date                          : Mon, 05 May 2025 05:15:08 GM


  Recommendation: See service error codes: https://learn.microsoft.com/graph/errors
DEBUG: [CmdletEndProcessing]: - New-MgGroup end processing.

Configuration

Name Value


PSVersion 7.5.1
PSEdition Core
GitCommitId 7.5.1
OS Darwin 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:39 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6020
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Other information

This change was made to no longer drop true/false, but I have no idea if this now dropped everything else instead.

@archoversight archoversight added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels May 5, 2025
@jolscr
Copy link

jolscr commented May 5, 2025

With Graph Release 2.27.0 you can use this to bypass issue : -displayName and -AdditionalProperties

$params = @{
	mailNickname = "ABCD"
	description = "Description ABCD"
	groupTypes = @(
		"Unified"
	)
	mailEnabled = $true
	securityEnabled = $true
	visibility = "Private"
	resourceBehaviorOptions = @(
		"WelcomeEmailDisabled"
	)
	"owners@odata.bind" = @(
		"https://graph.microsoft.com/v1.0/users/$Owner1ID"
		"https://graph.microsoft.com/v1.0/users/$Owner2ID"
	)
}

$groupeCreated = New-MgGroup -displayName "ABCD" -AdditionalProperties $params -ErrorAction:Stop -debug

@timayabi2020
Copy link
Contributor

timayabi2020 commented May 6, 2025

@archoversight please try with PowerShell 5 and let me know if it exhibits the same behavior?

@archoversight
Copy link
Author

archoversight commented May 6, 2025

@archoversight please try with PowerShell 5 and let me know if it exhibits the same behavior?

How do I install an older version of powerShell on macOS? Also why would I want to downgrade to an older version of PowerShell? I am using the latest and greatest in CI containers on Linux too, I don't want to attempt to downgrade those too.

Why would this work correctly in an older version of PowerShell?

If you'd like to provide installation instructions that are as simple as: "Run brew install <blah> and then run pwsh5" I'll be happy to test, but I don't have the time to try and dive into how to install and manage multiple versions of powershell on my system.

@jolscr
Copy link

jolscr commented May 7, 2025

@timayabi2020 always with PS7, I did some testing and found something interesting....

I created a group manually using Connect-MgGraph and New-MgGroup with all parameters... and it worked fine.

However, I did a second test from a new shell where I retrieved from a SharePoint site the metadata group to create using the Get-MgSiteListItem command and after that I call New-MgGroup but it throws the following error:"
New-MgGroup_Create: A value is required for property 'displayName' of resource 'Group'.

here is the loaded DLL: "Microsoft.Graph.Sites.private, Version=2.27.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Sites\2.27.0\bin\Microsoft.Graph.Sites.private.dll","False","True"

In a third test, if I run Import-Module Microsoft.Graph.Groups just before executing the Get-MgSiteListItem command, then New-MgGroup works

@timayabi2020
Copy link
Contributor

@jolscr thank you for sharing your findings. This is both interesting and a frustrating scenario because in my case if I encounter the same issue, all I need to do is a restart of the Powershell session and everything works ok. However, I am collecting feedback which is very helpful for the ongoing investigation.

@timayabi2020
Copy link
Contributor

Please update to the latest version 2.28.0

@timayabi2020 timayabi2020 added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels May 12, 2025
@jolscr
Copy link

jolscr commented May 13, 2025

just verified and it works fine with SDK version 2.28.0. Thank you very much!

@timayabi2020 timayabi2020 removed the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

3 participants