Navigation Menu

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

Set-AzureADUser - setting null value for attribute #166

Closed
akemball opened this issue Nov 15, 2017 · 39 comments
Closed

Set-AzureADUser - setting null value for attribute #166

akemball opened this issue Nov 15, 2017 · 39 comments

Comments

@akemball
Copy link

With the Set-MsolUser cmdlet, it is possible to set an attribute to "$null" to clear the value. E.g.
Set-Msoluser -userprincipalname -Mobile "$null" will clear whatever value is present for the Mobile phone.

But Set-AzureADUser -objectid -Mobile "$null" will generate an error.

set-AzureADUser : Error occurred while executing SetUser
Code: Request_BadRequest
Message: Invalid value specified for property 'mobile' of resource 'User'.
RequestId: e7c1d0eb-de00-4ab7-bf8b-5b7d9efbfa4e
DateTimeStamp: Wed, 15 Nov 2017 12:56:36 GMT
Details: PropertyName - mobile, PropertyErrorCode - InvalidLength
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:1 char:1
..........

Using AzureADPreview 2.0.0.137

Thanks

@RobdeJong
Copy link
Contributor

RobdeJong commented Nov 15, 2017 via email

@egbertvanderhout
Copy link

So... how do I empty those properties?

@thuld
Copy link

thuld commented Mar 8, 2018

Are you going to fix this defect? Currently do we need to "remove" values by setting the value to " " which is not perfect

@RobdeJong
Copy link
Contributor

RobdeJong commented Mar 8, 2018 via email

@RobdeJong
Copy link
Contributor

RobdeJong commented Mar 12, 2018 via email

@alex-3sr
Copy link

alex-3sr commented Aug 22, 2018

Hi,

can we have an update of this issue please ?

Thanks,
Alex

@TiloGit
Copy link

TiloGit commented Oct 18, 2018

same today with 2.0.1.16

Name              : azuread
Path              : C:\Program Files\WindowsPowerShell\Modules\azuread\2.0.1.16\Microsoft.Open.AzureAD16.Graph.PowerShell.dll
Description       : Azure Active Directory V2 General Availability Module.
                    This is the General Availability release of Azure Active Directory V2 PowerShell Module.
                    For detailed information on how to install and run this module from the PowerShell Gallery including prerequisites, please refer to
                    https://msdn.microsoft.com/powershell/gallery/readme
ModuleType        : Binary
Version           : 2.0.1.16

@jecarlsen
Copy link

We're doing this quite often on a number of customers users moving from onprem to Cloud only. We too use " " instead of NULL which still works.
Please don't break this 'feature' while we're waiting for a valid NULL assignment feature.

@memonjur
Copy link

Instead of this:
Set-AzureADUser -ObjectId -Mobile "$null"

Use this:
Set-AzureADUser -ObjectId -Mobile $null

@Terrenus
Copy link

Instead of this:
Set-AzureADUser -ObjectId -Mobile "$null"

Use this:
Set-AzureADUser -ObjectId -Mobile $null

Doesn't work for me. It doesn't give any error message prompt, but it doesn't neither clean the mobile field. I tried to wait a few minutes if it was caused by redundancy, but it didn't change after waiting 30 minutes.

@dougraheem
Copy link

@Terrenus try following, I had similar requirements.

 Set-AzureADUser -ObjectId $line.UserPrincipleName -City " "

Hope it helps.

@Terrenus
Copy link

Terrenus commented Jan 9, 2019

@dougraheem It works, kinda...

Unluckily we have a script from the background that recognise " " as a space, and not as a null or empty field.. Which is what I need. I guess I need to wait for an update or something similar from it.

Thanks for the hint :-)

@sankamm
Copy link

sankamm commented May 2, 2019

@dougraheem

any update since 2017?

@alexandermainz
Copy link

Any news with this issue?

I accidently set the "ImmutableId" field to a value and cannot use the "workaround" and set a white space in this field, because it has to be a unique value for alle AD identites in the tenant...

@sbgillett
Copy link

Why is this still not possible?

@emekm
Copy link

emekm commented Nov 27, 2019

after 2 years from the first request the BUG still exists.
It is really strange that we can set null from GUI, but not using remote powershell!

@rupeshprasad
Copy link

Any update on this? I am too stuck with this and would like to set filed value to null rather than " ".

@Tiagojaduarte
Copy link

It's been almost 3 years and still not a proper way of clearing the values of AAD user fields?
Common guys...

@urbantom
Copy link

Still not resolved. Shame you, guys.

@RikardStrand
Copy link

Encountered this bug today. Is there any ETA on when this will be resolved so we can use AzureAD cmdlets to clear (nullify) a value ?

Currently I need to make a lot of logic in my scripts to use both cmdlets but in some cases also use Graph API directly.

📢: @RobdeJong

@kitvek
Copy link

kitvek commented Aug 27, 2020

Also encountered this bug today. Any ETA on this?

@lwchkg
Copy link

lwchkg commented Sep 5, 2020

It's not a required attribute, why can't I unset it?

Set-AzureADUser : Error occurred while executing SetUser 
Code: Request_BadRequest
Message: Invalid value specified for property 'surname' of resource 'User'.
RequestId: 482c1001-db45-4e62-973a-4df0c2d4e216
DateTimeStamp: Sat, 05 Sep 2020 01:31:11 GMT
Details: PropertyName  - surname, PropertyErrorCode  - InvalidLength
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At D:\Documents\GoogleDrive\azuread\lib\SetUserInfo.ps1:104 char:5
+     Set-AzureADUser `
+     ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-AzureADUser], ApiException
    + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.SetUser

@kendrick3d
Copy link

I was able to find the answer to this one after some troubleshooting to make -OtherMails null. I ran into the same issues as above using $null, "$null", and " ", but I was able to modify the value and set it to null by setting the attribute to the following...

Set-AzureAdUser -ObjectID $id -OtherMails @{}

@iSnackyCracky
Copy link

I was able to find the answer to this one after some troubleshooting to make -OtherMails null. I ran into the same issues as above using $null, "$null", and " ", but I was able to modify the value and set it to null by setting the attribute to the following...

Set-AzureAdUser -ObjectID $id -OtherMails @{}

I'm facing basically the same issue as everyone else in this thread but with the FacsimileTelephoneNumber.
"", "$null" and $null don't work (first two generate "BadRequest" error, the last doesn't give an error but won't change the field)
Aetting it to @{} changes the field to System.Collection.Hashtable (which it is, but that doesn't really help either) :(

@Tiagojaduarte
Copy link

Why has this issue been closed?
Have you guys fixed this?

@akemball
Copy link
Author

No idea why this was closed - though the same user appeared to close several issues at the same time.
It is now 3 years since I originally raised this issue - and it still does not work. Very frustrating.

@sankamm
Copy link

sankamm commented Nov 25, 2020

@billmath Why has this issue been closed?

@54656452
Copy link

@billmath or @RobdeJong: Can we get some insight on why this long-standing issue was closed without a resolution despite previous comments indicating that a future release would resolve the matter?

I am attempting to transition all workflows to AzureAD commands instead of MSOL commands, but the inability to set an AAD attribute to a null value is a significant hurdle.

@psignoret
Copy link
Contributor

psignoret commented Apr 22, 2021

Hi everyone, just came across this issue myself, and found an approach that might help others around this issue. (Of course, this should only be useful to those who have a compelling reason to keep using the AzureAD module, instead of the Microsoft Graph PowerShell module.)

This workaround makes use of the fact that the ExtensionProperty parameter for Set-AzureADUser, which was probably intended for directory extensions, can be used to set any (valid) property of the user object. This gets past one of the issue at play here, where properties set to $null are not being emitted when the object is serialized to JSON.

$properties = [Collections.Generic.Dictionary[[String],[String]]]::new()
$properties.Add("telephoneNumber", [NullString]::Value)
Set-AzureADUser -ObjectId "user@example.com" -ExtensionProperty $properties

@5465645 I know this is a bit late to be commenting, but if you're doing a migration, you should really look to change to Microsoft Graph PowerShell, instead of Azure AD PowerShell.

@iSnackyCracky
Copy link

Hi @psignoret,

interesting workaround. It would still be nice to get this fixed properly.


Regarding your recommendation to using the Microsoft Graph module (Microsoft Graph PowerShell SDK):

I don't think this is a proper replacement for the AzureAD module (Azure Active Directory PowerShell for Graph). At least not for the majority of users or use-cases.
The Graph module is explicitly described as an SDK (Software Development Kit) and is more or less aimed at developers.
There is basically no documentation for the PowerShell module itself (besides how to install it), instead the Graph API and it's functions are documented.

The AzureAD module however is specifically designed to help with or automate administrative tasks.
The average AzureAD (or Microsoft 365) administrator probably doesn't know about the Graph API or how it's permissions (or scopes, as it's called in the documentation) work. (I myself included)

The Manage Microsoft 365 with PowerShell documentation also clearly states the AzureAD module is the "recommended" way (over the older MSOnline module (Microsoft Azure Active Directory Module for Windows PowerShell)) to connect to Microsoft 365 and administer user accouns, groups and licenses. It doesn't even mention the Graph SDK once - which probably has a reason.

Obviously the Graph module definitely has it's use-cases (i.e. for developers creating applications that integrate with M365) but I think the larger part of users (affected by this issue at least) will be admins that just want to automate part of their user management and don't want to get into understanding and working with an API.

@Borgquite
Copy link

Same issue here. Pretty sad that this has been closed.

@rossandrewyoung
Copy link

remove-azureaduserextension does the trick

@stromvirvel
Copy link

@RobdeJong This issue clearly isn't fixed. Please re-open.

@psignoret
Copy link
Contributor

@ChrisAtMAF @stromvirvel
A few things to keep in mind:

  1. This repo is for the documentation for the AzureAD module. Issues here are expected to be about the documentation, not about the module itself.
  2. That said, I've provided a fairly simple work-around above you can use to set a null value to an attribute: Set-AzureADUser - setting null value for attribute #166 (comment)
  3. The AzureAD module is not going to be getting any updates moving forward. It is strongly recommended for you to start moving to Microsoft Graph PowerShell: https://techcommunity.microsoft.com/t5/azure-active-directory-identity/automate-and-manage-azure-ad-tasks-at-scale-with-the-microsoft/ba-p/1942489

@nikolai-bravo
Copy link

As of July 2022, trying to set a field to $null still does not do anything. No error, but doesn't change the content of the field either. Attempting to set the field to "" still throws an error as well.

@jmeddy
Copy link

jmeddy commented Sep 16, 2022

I tried a few things for setting a blank ImmutableId value and finally got this one to work. It also avoids the "Set-MsolUser : Uniqueness violation. Property: SourceAnchor." error you would receive if trying to use a space or similar character more than once.

$var = ""
Set-MsolUser -UserPrincipalName user1@contoso.com -ImmutableId $var
Set-MsolUser -UserPrincipalName user2@contoso.com -ImmutableId $var

@polaran
Copy link

polaran commented Feb 14, 2023

I tried this one and it worked for me:
Set-AzureADUser -ObjectId -Mobile ' '

@Borgquite
Copy link

Borgquite commented Feb 14, 2023

@polaran FYI that's setting it to a single space, not to $null

We should all be using Graph now (see microsoftgraph/msgraph-sdk-powershell#833) and the old module won't be updated, I suspect. But if people insist, the best options I have found are:

Remove-AzureADUserExtension -ObjectId "user@example.com" -ExtensionName "telephoneNumber"

(NB despite the name, it clears the attribute value for a single user, not for all users - verified at https://stackoverflow.com/questions/61780722/remove-azureaduserextension-actual-result)

or

$properties = [Collections.Generic.Dictionary[[String],[String]]]::new()
$properties.Add("telephoneNumber", [NullString]::Value)
Set-AzureADUser -ObjectId "user@example.com" -ExtensionProperty $properties

@yllekz
Copy link

yllekz commented Feb 20, 2023

While this doesn't excuse the lack of progress on this, This is a decent workaround (this is an example of blanking out the "OtherMails" attribute):

$mguser = get-mguser -userid "person@mydomain.com"
Invoke-GraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/Users/$($MgUser.UserPrincipalName)" -Body '{"OtherMails": []}'

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