Skip to content

New-MgGroupMember fails with Invalid URL format #3154

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
12Knocksinna opened this issue Feb 21, 2025 · 25 comments
Closed

New-MgGroupMember fails with Invalid URL format #3154

12Knocksinna opened this issue Feb 21, 2025 · 25 comments
Assignees
Labels
Bug: PowerShell type:bug A broken experience

Comments

@12Knocksinna
Copy link

Describe the bug

After updating the SDK to V2.26, the New-MgGroupMember cmdlet fails with an "Invalid format specified in payload" error. It seems like there's an unresolved reference for the new group member ($ref) at the end of the URL generated for the request.

Expected behavior

I expect New-MgGroupMember to work!

How to reproduce

New-MgGroupMember -GroupId $GroupId -DirectoryObjectId $User.Id -debug
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:

Confirm
Are you sure you want to perform this action?
Performing the operation "New-MgGroupMember_CreateExpanded" on target "Call remote 'CreateGroupMember' operation".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
DEBUG: CmdletProcessRecordAsyncStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /groups/ad5b9740-0925-4254-8393-e47072fc5696/members/$ref
DEBUG: RequestCreated: /v1.0/groups/ad5b9740-0925-4254-8393-e47072fc5696/members/$ref
DEBUG: HeaderParametersAdded:
DEBUG: BodyContentSet:
DEBUG: BeforeCall:
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
New-MgGroupMember_CreateExpanded: Invalid URL format specified in payload.
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: CmdletEndProcessing:

SDK Version

V2.26

Latest version known to work for scenario above?

V2.25

Known Workarounds

Use a Graph request

Debug output

See above

Configuration

Name Value


PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Other information

The issue has been validated by several others.

@12Knocksinna 12Knocksinna added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Feb 21, 2025
@timayabi2020 timayabi2020 self-assigned this Feb 21, 2025
@timayabi2020 timayabi2020 added Bug: PowerShell and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Feb 21, 2025
@timayabi2020
Copy link
Contributor

@12Knocksinna apologies for the experience. We are working to resolve this issue.

@12Knocksinna
Copy link
Author

The problem here is that the same issue might exist for other cmdlets...

@timayabi2020
Copy link
Contributor

Yes, we have identified the issue, and PR has already been merged.

@AkosBakos
Copy link

When you plan to update the PS gallery?

@12Knocksinna
Copy link
Author

Were any other cmdlets found with the same problem? In other words, is the only update required for the Microsoft.Graoh.Groups module?

@12Knocksinna
Copy link
Author

Hopefully you can fix the Azure Automation issue reported in #3151 at the same time. The SDK shouldn't break stuff like this with a new version.

@Dankil90
Copy link

We have registered devices in Intune using Get-WindowsAutoPilotInfo.ps1 and are experiencing the same issue.

Are there any updates on a resolution or possible workaround?

@AkosBakos
Copy link

I was changing the code using direct a Graph API:
$egrpid = $aadGroup.Id
$edvcid = $aadDevice.id

                        #New-MgGroupMember -GroupId $aadGroup.Id -DirectoryObjectId $aadDevice.id
                        ##Use Graph
                        $eguri = "https://graph.microsoft.com/beta/groups/$egrpid/members/`$ref"
                        $json = @"

                        {
                            "@odata.id": "https://graph.microsoft.com/beta/directoryObjects/$edvcid"
                          }

"@
Invoke-MgGraphRequest -Method POST -Uri $eguri -Body $json -ContentType "application/json" -OutputType PSObject

Or you can switch to this commandlet:
https://www.powershellgallery.com/packages/get-windowsautopilotinfocommunity/5.0.4

@12Knocksinna
Copy link
Author

@Dankil90, have you tried reverting to V2.25 of the SDK

@big-bangus
Copy link

big-bangus commented Feb 24, 2025

I've just tried running New-MGGroupMember after reverting to 2.25.0, and it's still giving this "resource does not exist or one of its queried reference-property objects are not present" error when using syntax from a script I've had running without issue for months, the script only recently started having issues after upgrading my version of the Graph SDK on my device.
I've also noticed, that when running New-MgGroupMember -? and clicking the Microsoft Learn link, it directs to a 404 page, acting as if the command is gone: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.groups/new-mggroupmember

@12Knocksinna
Copy link
Author

12Knocksinna commented Feb 24, 2025

@diabeetus01 I just ran New-MgGroupMember on my PC with V2.25 and it worked perfectly.

I suspect that some vestiges of V2.26 are lingering. To remove V2.26, I uninstalled the module, removed all traces of module files from the PC, and rebooted. I then reinstalled V2.25. All went well thereafter.

@big-bangus
Copy link

@diabeetus01 I just ran New-MgGroupMember on my PC with V2.25 and it worked perfectly.

I suspect that some vestiges of V2.26 are lingering. To remove V2.26, I uninstalled the module, removed all traces of module files from the PC, and rebooted. I then reinstalled V2.25. All went well thereafter.

Interesting, I just went through those steps and after reboot its still giving the same failures, tested with a few devices and with PS7 as well, wouldn't be shocked if its an issue on device still but version installed reports 2.25.0.

Will keep poking around to see what I can figure out, as it seems New-MgGroupMember was the only way to add a Device ID to a Group, since I haven't found a working odata.id string yet to pass the device ID to that works with New-MgGroupMemberByRef.

@anguzz
Copy link

anguzz commented Feb 24, 2025

I've just tried running New-MGGroupMember after reverting to 2.25.0, and it's still giving this "resource does not exist or one of its queried reference-property objects are not present" error when using syntax from a script I've had running without issue for months, the script only recently started having issues after upgrading my version of the Graph SDK on my device. I've also noticed, that when running New-MgGroupMember -? and clicking the Microsoft Learn link, it directs to a 404 page, acting as if the command is gone: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.groups/new-mggroupmember

Adding onto this to say I am experiencing the same behavior with 2.26.0 with scripts working previously. Reverting did help but caused issues with other scripts that only seemed to work on 2.26.0

@sccmskin
Copy link

Same issue here. Getting invalid URL format in payload when attempting to add a device to an AAD group.

@JeremyTBradshaw
Copy link

Want to share that I noticed this issue with the V2.26 of Microsoft.Graph.Identity.Governance particularly when calling New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest

New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest_Create: 
Line |
  22 |      New-MgRoleManagementDirectoryRoleAssignmentScheduleRequest -BodyP …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The resource '' is invalid.

Status: 400 (BadRequest)
ErrorCode: DirectoryScopeId
Date: 2025-02-25T15:04:29

Headers:
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : bba84732-ee33-487d-bef0-f65dd7063c99
client-request-id             : d4525c46-1b3f-458b-94ba-d4c7b779beaa
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"Canada East","Slice":"E","Ring":"3","ScaleUnit":"000","RoleInstance":"QB1PEPF00005798"}}
Date                          : Tue, 25 Feb 2025 15:04:28 GMT

Meanwhile (I've supplied a "/" (slash), not "" (blank/null/empty):

[PS] > $params.DirectoryScopeId
/

The only reason why I think this is the same issue is that @timayabi2020 closed #3173 and referenced this issue.

@12Knocksinna
Copy link
Author

When going back to V2.25, it's really important to expunge all traces of V2.26 from a PC. Delete all the files, empty the wastebasket, etc. Reboot to ensure that no open files block deletion. Delete again if necessary. Get back to bare metal and then install V2.25... that's what I did and everything runs just fine since.

@sccmskin
Copy link

I'm also using the Get-WindowsAutopilotInfo script. I tried to force the install of the modules with -RequiredVersion 2.25.0 but it appears that the WindowsAutopilotIntune module is installing version 2.26.0 during installation. I don't have a workaround at this time, but will continue to work on it and if I find something, I'll post it here.

@timayabi2020
Copy link
Contributor

Hi all please upgrade to version 2.26.1 and let us know if you are still experiencing the same challenge of / being truncated.

@timayabi2020 timayabi2020 added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Feb 26, 2025
@lucien1264
Copy link

@timayabi2020 , at least for New-MgGroupmember the issue is solved. I didn't yet test anything else.

Is it correct that Microsoft.Graph.DeviceManagement.Actions is on 2.25.0 ?

@sccmskin
Copy link

It's working for me now. At least using the WindowsAutopilotIntune module with the Get-WindowsAutopilotInfo script

@AkosBakos
Copy link

With the new module release (2.26.1), the process should work again.

@squeekymouse89
Copy link

With the new module release (2.26.1), the process should work again.

It was working 2 hours ago. I'm not sure if its now broken again.

@JeremyTBradshaw
Copy link

Nice job getting this one out so quick @timayabi2020 - solved my issue with Microsoft.Graph.Identity.Governance ! Thanks very much.

@fug4zi
Copy link

fug4zi commented Feb 26, 2025

It's now working with 2.26.1

But that should affects all versions below 2.26.1? I've tested with 2.26.0 and 2.25.0

@fabrizio-lamari
Copy link

fabrizio-lamari commented Mar 4, 2025

For me it's still not working, for us it's breaking when creating a new Teams and passing an owner, it's still working well by using V2.25.0. Should that be fixed with V2.26.1?

$NewGroupParams = @{
			"DisplayName" = "$newTeamId"
			"mailNickname"=  "$newTeamId"
			"Description" = "$teamsDescription"
			"Visibility" = "private"
			"owners@odata.bind" = @(
									"https://graph.microsoft.com/v1.0/users/" + $($ownerteamuser.UserPrincipalName)
								)
			"groupTypes" =  @(
							"Unified"
							)
			"mailEnabled" =  "true"
			"securityEnabled" = "false"
		}

		Write-Host "New group creating..."
		try {
			$NewGroup = New-MgGroup -BodyParameter $NewGroupParams -ErrorAction Stop
		}
		catch {
			Write-Error "ERROR: "$_.Exception.Message
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: PowerShell type:bug A broken experience
Projects
None yet
Development

No branches or pull requests