microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
716 stars 172 forks source link

Get-MgGroup v2.13.1 returns spurious ResponseHeader object #2584

Closed jaspain closed 9 months ago

jaspain commented 9 months ago

Description

Get-MgGroup -GroupId v2.13.1 returns a System.Object[] with two elements: a Microsoft.Graph.PowerShell.Models.MicrosoftGraphGroup and a Microsoft.Graph.PowerShell.ResponseHeaders.ResponseHeader. The documentation Get-MgGroup states that the output should be a single object of the former type.

Similar behavior occurs with Update-MgGroup and Get-MgUser. Other cmdlets not tested.

To reproduce

Execute Get-MgGroup -GroupId <id>, where <id> is any valid group Id.

Expected behavior

Return only a single Microsoft.Graph.PowerShell.Models.MicrosoftGraphGroup object.

Debug output

DEBUG: [CmdletBeginProcessing]: - Get-MgGroup begin processing with parameterSet 'Get'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', TokenCredentialType: 'ClientCertificate', ContextScope: 'Process', AppName: 'PowerShell System Administration'.
DEBUG: [Authentication]: - Scopes: [TeamSettings.ReadWrite.All, Device.ReadWrite.All, Channel.Delete.All, User.ReadWrite.All, AppCatalog.ReadWrite.All, Group.ReadWrite.All, DeviceManagementServiceConfig.ReadWrite.All, Mail.Send, Organization.Read.All, ChannelMember.ReadWrite.All, ChannelSettings.ReadWrite.All, AuditLog.Read.All, DeviceManagementConfiguration.ReadWrite.All, DeviceManagementApps.ReadWrite.All].
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.microsoft.com/v1.0/groups/<redacted>

Headers:
FeatureFlag                   : 00000043
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22631; en-US),PowerShell/7.4.1
Accept-Encoding               : gzip
SdkVersion                    : graph-powershell/2.13.1
client-request-id             : <redacted>

Body:

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

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : <redacted>
client-request-id             : <redacted>
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"South Central US","Slice":"E","Ring":"5","ScaleUnit":"000","RoleInstance":"SA2PEPF00002DF5"}}
x-ms-resource-unit            : 1
OData-Version                 : 4.0
Date                          : Sat, 10 Feb 2024 13:56:09 GMT

Body:
{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups/$entity",
  "id": "<redacted>",
  "deletedDateTime": null,
  "classification": null,
  "createdDateTime": "2023-05-16T18:04:25Z",
  "creationOptions": [],
  "description": null,
  "displayName": "Faculty-Staff, All",
  "expirationDateTime": null,
  "groupTypes": [
    "DynamicMembership"
  ],
  "isAssignableToRole": null,
  "mail": null,
  "mailEnabled": false,
  "mailNickname": "fe445c72-3",
  "membershipRule": "(user.department -startsWith \"FacStaff\") and (user.department -notContains \"TestUser\")",
  "membershipRuleProcessingState": "On",
  "onPremisesDomainName": null,
  "onPremisesLastSyncDateTime": null,
  "onPremisesNetBiosName": null,
  "onPremisesSamAccountName": null,
  "onPremisesSecurityIdentifier": null,
  "onPremisesSyncEnabled": null,
  "preferredDataLocation": null,
  "preferredLanguage": null,
  "proxyAddresses": [],
  "renewedDateTime": "2023-05-16T18:04:25Z",
  "resourceBehaviorOptions": [],
  "resourceProvisioningOptions": [],
  "securityEnabled": true,
  "securityIdentifier": "<redacted>",
  "theme": null,
  "visibility": null,
  "onPremisesProvisioningErrors": [],
  "serviceProvisioningErrors": []
}

DEBUG: [CmdletEndProcessing]: - Get-MgGroup end processing.

Module version

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.13.1                Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-M…
Script     2.13.1                Microsoft.Graph.Groups              {Add-MgGroupDriveListContentTypeCopy, Add-MgGroup…

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
jaspain commented 9 months ago

As it applies to Get-MgUser, this bug creates a breaking change in about 20 of my production scripts, so I'm hoping that you are able to address it quickly. Thanks.

dagarwal-mitre commented 9 months ago

This issue also applies to the Get-MgBetaUserCount, and occurred when I updated from v2.12 to v2.13.1. Attached is a picture of the command which is causing the issue and the associated output: 1a3fbd39-2560-4518-a941-8e8f34ee2c39

AlanFlorance commented 9 months ago

This also applies to MgApplication, it now returns the app object along with ResponseHeaders

kichristensen commented 9 months ago

I have seen the same for multiple resources, I honestly think this release is so buggy, or if this is by design, introduces so many undocumented changes that it should be removed from PSGallery until it have been fixed, or as a minimum bump the version to indicate a major breaking change

VaclavK commented 9 months ago

This also applies to MgApplication, it now returns the app object along with ResponseHeaders

I see diff between Get-MgApplication with either filter or by ApplicationId - filter call returns expected , app id returns the headers as well

justinmontgomeryCF commented 9 months ago

2.13.1 is not working for me.

Get-MGUser still returns ResponseHeaders, as does Update-MgDirectoryOnPremiseSynchronization

BohrenAn commented 9 months ago

Same problem here. The Array contains the Responseheaders. Array should be only 1 but has a count of 2. Therefore the $Users[1].DisplayName is Empty.

$Users = Get-MgUser -UserId a.bohren@icewolf.ch $Users.Count

Foreach ($User in $Users) { $DisplayName = $User.DisplayName Write-Host "DisplayName: $DisplayName" }

Same Problem exists in Version 2.14.0

Kind Regards Andres

jaspain commented 9 months ago

I'm confirming the observation of @BohrenAn that this issue has not been fixed in v2.14.0. In fact, rather than returning just a ResponseHeader object along with the expected user or group object , Get-MgUser and Get-MgGroup are now returning a hashtable with various properties of the query/response as the second element of the returned array:

----                           -----
client-request-id              {<redacted>}
x-ms-resource-unit             {1}
request-id                     {<redacted>}
Vary                           {Accept-Encoding}
Date                           {Sun, 18 Feb 2024 13:34:59 GMT}
Strict-Transport-Security      {max-age=31536000}
OData-Version                  {4.0}
x-ms-ags-diagnostic            {{"ServerInfo":{"DataCenter":"South Central US","Slice":"E","Ring":"5","ScaleUnit":"002…
Cache-Control                  {no-cache}
Transfer-Encoding              {chunked}

I did not test other cmdlets. I think my best option for now is to roll back to v2.12.0 until this is fixed.

CarolKigoonya commented 9 months ago

We are working on a fix on this issue #2600

skellyatsnhu commented 9 months ago

I'm running into really awkward behavior when using null checks on get-mguser results. It seems even if there is no value returned, it returns a huge array of blank nothingness which is not what it did previously. Details in #2600

peterboba commented 9 months ago

Confirming this issue in 2.14.0 with Get-MgServicePrincipalAppRoleAssignment

kpinel commented 9 months ago

There is a workaround, but like many here, I have a ton of scripts to update $CheckTeam = Get-MgGroup -Filter "Id eq '$TeamId'" -ErrorAction Stop

This would go for the other cmdlets with this issue.

I'm just thankful that I haven't updated my runbook modules yet!

jaspain commented 9 months ago

@kpinel I have resisted using such a workaround, opting to roll back to 2.12.0 instead. This has been broken for about a week, and it looks like the developers are working on fixing it as we speak. I intend to wait it out.

salbeck-sit commented 9 months ago

Apparently @timayabi2020 posted a message in this thread some 5 hours ago saying that upgrading to 2.14.1 would solve it but that message appears to have been pulled. And now version 2.4.1 (4, not 14) has been released. It appears that the issue isn't quite sorted yet.

timayabi2020 commented 9 months ago

Hi @salbeck-sit the patch 2.14.1 resolves the issue. Please install and confirm. Thanks

salbeck-sit commented 9 months ago

Thanks @timayabi2020, I got it.

jaspain commented 9 months ago

With v2.14.1, Get-MgUser -UserId <id> and Get-MgGroup -GroupId <id> are again returning single [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser] and [Microsoft.Graph.PowerShell.Models.MicrosoftGraphGroup] objects, respectively, as expected.

@timayabi2020 The online documentation Get-MgUser hasn't yet been updated, and it differs from Get-Help -Name Get-MgUser -Full. While I may not understand correct usage, I don't think the ResponseHeadersVariable parameter is working as expected. It doesn't modify the supplied variable's value with the response headers. For example:

PS> $r = 'Initial Value'
PS> $u = Get-MgUser -UserId user@mydomain.com -ResponseHeadersVariable r
PS> $u.GetType().FullName
Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser
PS> $r
Initial Value

See Adds an optional -RHV parameter that will assign response headers to a variable (Value provided to the optional RHV parameter) #2604

timayabi2020 commented 9 months ago

@jaspain thanks for pointing that out. The parameter is now working as expected in version 2.15.0.

image

Please note that -RHV is the alias for -ResponseHeadersVariable

jaspain commented 9 months ago

@timayabi2020 Thank you. I'm confirming that -ResponseHeadersVariable is working as expected in v2.15.0. I think you can close this issue 2584.