Remove or Clear Property or Set Null value using Set-AzureADUser cmdlet

We can use the Set-AzureADUser cmdlet to update Microsoft 365 user properties in Azure AD. This command works fine when you set a value for any property of a user, but to clear or empty the property by setting $null is currently not supported.

With the MSOnline PowerShell module, we can use the Set-MsolUser cmdlet to clear an attribute value by setting “$null”. The below command clears the value that is present for the Mobile phone attribute.

Set-Msoluser -UserPrincipalName "[email protected]" -MobilePhone "$null"

The same case is not supported (or yet to be supported) with the Set-AzureADUser cmdlet which comes under the Azure AD PowerShell V2 module (Powered by Microsoft Graph API). The “empty space” is also not allowed to set this property. You can refer to this thread: https://github.com/Azure/azure-docs-powershell-azuread/issues/166.

As a workaround we can use the ExtensionProperty parameter in the Set-AzureADUser cmdlet, this parameter is probably intended to update directory extensions, but we can also use it to set any valid property of the user object.

The below commands clear the Mobile attribute in the given user.

$properties = [Collections.Generic.Dictionary[[String],[String]]]::new()
$properties.Add("Mobile", [NullString]::Value)
Set-AzureADUser -ObjectId "[email protected]" -ExtensionProperty $properties
Advertisement