You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Support Setting Fields to null] Unable to set BusinessPhones or MobilePhone fields to $null #833
When trying to set BusinessPhones or MobilePhone values to $null, like so: Update-MgUser -UserId $MgUser.UserPrincipalName -MobilePhone $null -BusinessPhones $null
It throws an error: Update-MgUser_UpdateExpanded: Invalid value specified for property 'mobilePhone' of resource 'User'.
I've fixed this for now by using an alternative command: Invoke-GraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/Users/$($MgUser.UserPrincipalName)" -Body '{"businessPhones": [],"mobilePhone": null}'
Hope this helps someone else in a similar need and more so, the Update-MgUser cmdlet is fixed.
Please push this on top of requirement list, $null should be supported as we have in Set-MSOLUser. The workaround needs extra handling and additional calls.
It would be good if an ETA is shared.
Reacted by Luca Hostettler, yllekz, Julian Pawlowski, Chris-Tonev and Francis Gulotta
yllekz , Thanks for the workaround guide. However, this workaround requires an extra command to be executed.
It would be great if you could set $null in Update-MgUser like in the MSOL module without leaving this problem.
Seriously I am shocked that the APIs do not handle nulls, with this and the deleted items call failing to work at all, it calls into question the quality of this module. I wrote my own interface class a couple of year back because of the deleted items thing but this time I am attempting to use the new module, but come on guys, this is basic stuff. Now we have to have a special case for any null (and deleted items), how many more will I find?
Reacted by enthusol, ƘɌỈSƬƠƑ, Julian Pawlowski, Chris-Tonev and PrizmaticAtmos
This is my workaround, I have a hashtable of values to update... there might be a more efficient way of setting up the hashtables, I've not had time to look yet.
$nullProperties = @{}
$notNullProperties = @{}
# Nulls require special processing, so need to split the values that are null and not null into a separate hashtables
$properties.GetEnumerator() | foreach {
if ([string]::IsNullOrEmpty($_.Value)) {
$nullProperties.add($_.name, $_.value)
} else {
$notNullProperties.add($_.name, $_.value)
}
}
# (aadUser is a user object from Get-MgUser)
# Not null properties
if ($notNullProperties.count -gt 0) {
if ((Update-MgUser -UserId $aaduser.Id -BodyParameter $notNullProperties -PassThru) -eq $false) {
throw "Update user failed"
}
}
# Null properties
if ($nullProperties.count -gt 0) {
$response = Invoke-MgGraphRequest -Method PATCH -Uri "v1.0/Users/$($aaduser.id)" -Body $nullProperties -StatusCodeVariable ResponseStatusCode
if ($responsestatuscode -ne 204) {
throw "Clearing user properties failed"
}
}
changed the title [-]Unable to set BusinessPhones or MobilePhone fields to $null[/-][+][Support Setting Fields to null] Unable to set BusinessPhones or MobilePhone fields to $null[/+]on Jul 19, 2023
If there is no timeline to get this fixed with all the update-mguser properties, can we at least get the documentation updated to call out that you can't clear values once they are set and you should call the API directly as a workaround?
Reacted by PrizmaticAtmos, Jussi Palo, Francis Gulotta and davidtrevor23
Activity
Machsol-Usman commentedon Jun 23, 2022
Please push this on top of requirement list, $null should be supported as we have in Set-MSOLUser. The workaround needs extra handling and additional calls.
It would be good if an ETA is shared.
yllekz commentedon Jul 22, 2022
This needs to be updated/fixed such that the "OtherMails" attribute can also be set to null.
This module needs to be at parity with MSOnline before it is retired. Please expedite.
tyteen4a03 commentedon Oct 27, 2022
Any updates to this?
rui0122 commentedon Oct 27, 2022
Invoke-GraphRequest fails on the latest module version 1.14.0. You can use Invoke-MgGraphRequest instead.
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/uers/ -Body "{
"mobilePhone": null }"As multiple customers are facing this issue, please fix this asap.
peombwa commentedon Nov 2, 2022
ruimurakami-MSFT (@rui0122), the workaround works well for me in

v1.14.0:The issue is with the spelling of
usersin the-Uri.testtesttaro commentedon Feb 20, 2023
When will this issue be fixed?
yllekz commentedon Feb 20, 2023
While this doesn't excuse the lack of progress on this, This is a decent workaround:
testtesttaro commentedon Feb 20, 2023
yllekz , Thanks for the workaround guide. However, this workaround requires an extra command to be executed.
It would be great if you could set $null in Update-MgUser like in the MSOL module without leaving this problem.
yllekz commentedon Feb 21, 2023
It's only one command. The first line is just a variable assignment for convenience. You don't have to write it that way if you don't want to.
peombwa commentedon Feb 21, 2023
We currently do not support setting properties to null due to a design limitation with the code generator - Azure/autorest.powershell#961.
As a workaround, please use the
Invoke-GraphRequestas suggested above.peombwa commentedon Feb 22, 2023
@nathankascopgr, please open a question at https://developer.microsoft.com/en-us/graph/support to get assistance from the API owner.
DougChandler commentedon Apr 19, 2023
Seriously I am shocked that the APIs do not handle nulls, with this and the deleted items call failing to work at all, it calls into question the quality of this module. I wrote my own interface class a couple of year back because of the deleted items thing but this time I am attempting to use the new module, but come on guys, this is basic stuff. Now we have to have a special case for any null (and deleted items), how many more will I find?
DougChandler commentedon Apr 19, 2023
This is my workaround, I have a hashtable of values to update... there might be a more efficient way of setting up the hashtables, I've not had time to look yet.
[-]Unable to set BusinessPhones or MobilePhone fields to $null[/-][+][Support Setting Fields to null] Unable to set BusinessPhones or MobilePhone fields to $null[/+]worldsdream commentedon Dec 1, 2023
We really need this!
jpawlowski commentedon Dec 9, 2023
+1
npherson commentedon Jan 5, 2025
If there is no timeline to get this fixed with all the update-mguser properties, can we at least get the documentation updated to call out that you can't clear values once they are set and you should call the API directly as a workaround?