Clear user information in Microsoft 365 Admin Center

Rohit 0 Reputation points
2023-07-13T11:09:33.35+00:00

I am trying below PS script but information is not cleared in Managed Contact Information (Microsoft 365 Admin Center) for specific user.

Connect to Microsoft Graph

Connect-MgGraph

Get the user by UserPrincipalName

$user = Get-MgUser -UserId $UserPrincipalName

Clear the desired user properties

$user.Department = $null

$user.OfficeLocation = $null

$user.StreetAddress = $null

$user.City = $null

$user.State = $null

$user.Country = $null

$user.PostalCode = $null

$user.MobilePhone = $null

$user.DisplayName = $null

$user.MailNickName = $null

$user.JobTitle = $null

$user.GivenName = $null

$user.BusinessPhones = $null

Update the user with the cleared properties

Update-MgUser -Id $user.Id -UserPrincipalName $user.UserPrincipalName -User $user

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,346 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,950 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,854 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Pauline Mbabu 5 Reputation points Microsoft Employee
    2023-08-02T09:15:20.9133333+00:00

    The SDK currently does not support nullifying Values. See this thread for reference https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/852

    As a workaround try the following: Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/Users/{USER-ID}" -Body @{Department= $null} to nullify properties.

    1 person found this answer helpful.
    0 comments No comments