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

Update-MGUser -agegroup doesn't allow null value despite documentation

Open skellyatsnhu opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like The Update-MgUser documentation states that -AgeGroup accepts null as one of its values. In practice, it does not, erroring out. What does work is adult, minor, and notadult.

Describe alternatives you've considered update-mguser -userid "[email protected]" -agegroup null update-mguser -userid "[email protected]" -agegroup "null" update-mguser -userid "[email protected]" -agegroup $null

Invoke-GraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/Users/$($myupn)" -Body '{"AgeGroup": []}' ^This also fails with effectively the same error.

Additional context n/a

skellyatsnhu avatar Feb 21 '24 19:02 skellyatsnhu

Just confirming that I've replicated your issue, and tried a few different things as well (null, $null, 'null', "'null'", '$null', `$null)

I've been able to successfully set this via Graph Explorer, so it does appear to be an issue with the SDK: image

It seems to need an unquoted value for null, where the values for Minor, NotAdult, and Adult need quotes around them. i.e. Correct: null Incorrect: "null"

Correct: "Minor", "NonAdult", "Adult" Incorrect: Minor, NonAdult, Adult

It appears as though the SDK is automatically adding quotes around the null (debug below): image

SeniorConsulting avatar Feb 21 '24 21:02 SeniorConsulting

Unfortunately, this problem has been known for some years (see this issue from 2017 on the AzureAD Powershell repo) You were right to use Invoke-GraphRequest as it is the suggested workaround. The command that you're looking for would be : Invoke-GraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/users/$myupn" -Body '{"AgeGroup": null}'

quentinmarois avatar Feb 23 '24 08:02 quentinmarois

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.