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

Update-MgUser Unable to Clear onPremisesImmutableId

Open jamesshuriff opened this issue 1 year ago • 9 comments

Describe the bug The Update-MgUser cmdlet cannot clear the onPremisesImmutableId property.

To Reproduce Execute a command such as: Update-MgUser -UserId [UserId] -OnPremisesImmutableId $null

Expected behavior The property should clear.

The payload generated by Update-MgUser is: {"onPremisesImmutableId": ""} It should be: {"onPremisesImmutableId":null}

Module Version 2.11.1

Environment Data

Name                           Value
----                           -----
PSVersion                      5.1.20348.2110
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.2110
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

jamesshuriff avatar Jan 08 '24 03:01 jamesshuriff

Hi @jamesshuriff kindly share the debug information for this request by providing a -Debug parameter at the end of the command.

timayabi2020 avatar Apr 03 '24 09:04 timayabi2020

DEBUG: [CmdletBeginProcessing]: - Update-MgUser begin processing with parameterSet 'UpdateExpanded'.
DEBUG: [Authentication]: - AuthType: 'Delegated', TokenCredentialType: 'DeviceCode', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph Command Line Tools'.
DEBUG: [Authentication]: - Scopes: [openid, profile, User.Read, User.ReadWrite.All, email].

Confirm
Are you sure you want to perform this action?
Performing the operation "Update-MgUser_UpdateExpanded" on target "Call remote 'PATCH /users/{user-id}' operation".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PATCH

Absolute Uri:
https://graph.microsoft.com/v1.0/users/7ad49bfe-d327-4ada-9c2f-fb7ec21b8045

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.15.0
client-request-id             : 16382a65-e10e-4367-9217-b4e7583308b3

Body:
{
  "onPremisesImmutableId": ""
}


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

Status Code:
BadRequest

Headers:
Cache-Control                 : no-cache
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : 8ff2d280-34ca-48d8-93c4-6890642759f9
client-request-id             : 16382a65-e10e-4367-9217-b4e7583308b3
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"Canada Central","Slice":"E","Ring":"3","ScaleUnit":"002","RoleInstance":"YT2PEPF000001A4"}}
x-ms-resource-unit            : 1
Date                          : Mon, 08 Apr 2024 12:48:10 GMT

Body:
{
  "error": {
    "code": "Request_BadRequest",
    "message": "Invalid value specified for property 'onPremisesImmutableId' of resource 'User'.",
    "details": [
      {
        "code": "InvalidLength",
        "message": "The onPremisesImmutableId should be between 1 and 256 characters.",
        "target": "onPremisesImmutableId"
      }
    ],
    "innerError": {
      "date": "2024-04-08T12:48:10",
      "request-id": "8ff2d280-34ca-48d8-93c4-6890642759f9",
      "client-request-id": "16382a65-e10e-4367-9217-b4e7583308b3"
    }
  }
}


Update-MgUser_UpdateExpanded: Invalid value specified for property 'onPremisesImmutableId' of resource 'User'.

Status: 400 (BadRequest)
ErrorCode: Request_BadRequest
Date: 2024-04-08T12:48:10

Headers:
Cache-Control                 : no-cache
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : 8ff2d280-34ca-48d8-93c4-6890642759f9
client-request-id             : 16382a65-e10e-4367-9217-b4e7583308b3
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"Canada Central","Slice":"E","Ring":"3","ScaleUnit":"002","RoleInstance":"YT2PEPF000001A4"}}
x-ms-resource-unit            : 1
Date                          : Mon, 08 Apr 2024 12:48:10 GMT

DEBUG: [CmdletEndProcessing]: - Update-MgUser end processing.

jamesshuriff avatar Apr 08 '24 12:04 jamesshuriff

Still not possible in SDK v2.17.0 so it might be something that the API-owner doesn't want or doesn't know how to do ?

Here's a working way to do it: Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/Users/$($userObj.id)" -Body @{OnPremisesImmutableId = $null} -ErrorAction Stop

salbeck-sit avatar Apr 11 '24 07:04 salbeck-sit

Still not possible in SDK v2.17.0 so it might be something that the API-owner doesn't want or doesn't know how to do ?

Here's a working way to do it: Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/Users/$($userObj.id)" -Body @{OnPremisesImmutableId = $null} -ErrorAction Stop

Or they were not aware of it. Hence, the bug report.

jamesshuriff avatar Apr 11 '24 13:04 jamesshuriff