Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-MgUser - setting null values for attributes #852

Closed
yukieryu opened this issue Sep 9, 2021 · 10 comments
Closed

Update-MgUser - setting null values for attributes #852

yukieryu opened this issue Sep 9, 2021 · 10 comments
Milestone

Comments

@yukieryu
Copy link

yukieryu commented Sep 9, 2021

With the Set-MsolUser cmdlet, it is possible to set an attribute to "" to clear the value.
E.g. Set-MsolUser -LastName "" will clear whatever value is present for the last name.

However, Update-MgUser -UserId -Surname "" will generate error as below -
Also attempted Update-MgUser -UserId -Surname $null but the same error.

Update-MgUser : Invalid value specified for property 'mobilePhone' of resource 'User'.
At line:1 char:1
Update-MgUser -UserId 3d5f9e6a-c8e6-4ab3-8167-d56f0cd3b215 -MobilePho ...

    + CategoryInfo          : InvalidOperation: ({ UserId = 3d5f...oftGraphUser1 }:<>f__AnonymousType47`2) [Update-MgUser_Up
   dateExpanded], RestException`1
    + FullyQualifiedErrorId : Request_BadRequest,Microsoft.Graph.PowerShell.Cmdlets.UpdateMgUser_UpdateExpanded

On the side note, Set-AzureADUser -objectid -Surname "" will generate an error.
https://github.com/Azure/azure-docs-powershell-azuread/issues/166

@ghost ghost added the ToTriage label Sep 9, 2021
@peombwa
Copy link
Member

peombwa commented Oct 7, 2021

The SDK does not currently support nullifying values to how the deserializer works. We will use this issue to track this as a feature request.

@peombwa peombwa added this to the Backlog milestone Oct 7, 2021
@yukieryu
Copy link
Author

Thank you for the response and using this as a feature request.

@Chris-Tonev
Copy link

Following.

@gagwithgaffer
Copy link

gagwithgaffer commented Dec 27, 2021

I'm having the same issue trying to clear the password policy for an Azure AD user through the MS Graph SDK.

https://docs.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=http

The password policy compromises two strings:

DisablePasswordExpiration, DisableStrongPassword

I can only remove one of the two string options at any one time by updating the user and writing over the previous configuration. It's not possible to overwite the policy with an empty string or null. This means any user who has had a password policy set previously is now stuck with at least one of the options for ever!

@JakeMoe
Copy link

JakeMoe commented Jan 6, 2022

FWIW, this appears to be a duplicate of #833.

@gagwithgaffer You could try Invoke-GraphRequest as mentioned in that other issue. It worked for me with the City attribute.

@peombwa
Copy link
Member

peombwa commented Jan 7, 2022

Closing as duplicate of #833. We are tracking the feature request in #833.

As a workaround, one can use Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/Users/{USER-ID}" -Body @{Surname = $null} to nullify properties.

@rui0122
Copy link

rui0122 commented Oct 27, 2022

The workaround "Invoke-MgGraphRequest" fails on the latest module 1.14.0. You can run "Invoke-MgRestMethod" instead.

@peombwa
Copy link
Member

peombwa commented Nov 2, 2022

@rui0122, please open a new issue with the repro steps and the error message.

The workaround works well for me in v1.14.0:
image

@blb8547
Copy link

blb8547 commented Jan 19, 2024

@yukieryu I found a workaround but I have not tested your exact situation. If you run the MG command with -bodyparameter and define your attributes in a hash table you can set "attribute" = @() and that will null it out. Let me know if that works for you as well.

@bastienperez
Copy link

Any chance that the future SDK will finally support "$null"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants