microsoftgraph / msgraph-sdk-powershell

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

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

Open skellyatsnhu opened 8 months ago

skellyatsnhu commented 8 months ago

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 "somebody@domain.com" -agegroup null update-mguser -userid "somebody@domain.com" -agegroup "null" update-mguser -userid "somebody@domain.com" -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

SeniorConsulting commented 8 months ago

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

quentinmarois commented 8 months ago

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}'

microsoft-github-policy-service[bot] commented 8 months ago

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.