Clearing an attribute for all users through Microsoft Graph

Certain Azure AD attributes, such as businessPhones, are not available through the Azure AD PowerShell module. Here is a super quick way to work with the graph using PowerShell, without needing separate app registrations etc.

When signing into the Microsoft Graph Explorer, you can change scope and stuff to generate an access token that can be used towards the Graph. Because the access token is listed in the url, it is SUPER easy to just copy and use in PowerShell. The token is valid for one hour only.

Start by navigating to Microsoft Graph Explorer and clicking the sign in button on the left.

Sign in with the user you want to be the actor of your requests, such as a global admin.

Copy the url in the browser (it will contain #access-token=).

The below PowerShell will find the access token from the URL on the clipboard and clear the businessPhones attribute.

Function ConvertFrom-Base64 {

        return [System.Text.Encoding]::UTF8.GetString(([System.Convert]::FromBase64String($Base64String)));


   Function to simply return the access token from the graph explorer URL
function Get-AccessTokenFromGraphExplorerUrlOnClipboard

        $first = $true
        do {
            if(!$first) {
                Sleep -Seconds 1   
            $first = $false 

            Write-Verbose "Trying to get Graph Explorer URL from clipboard"
            $url = Get-Clipboard
            if($url -ne $null -and $url.StartsWith("")) {
                $token = $url -split "[=&]" | Select -Index 1
        } while($token -eq $null -or !$token.StartsWith("ey"))


$token = Get-AccessTokenFromGraphExplorerUrlOnClipboard -Verbose

$users = @()
$url = "`$top=999"
do {
    $result = Invoke-RestMethod $url -Headers @{Authorization = "Bearer $token"}  -Verbose
    $users += $result.value
    $url = $result.'@odata.nextLink'
} while ($url)

$users | ? businessPhones | foreach {
    $body = '{"businessPhones" : []}'
    invoke-restmethod "$($" -Method Patch -body $body -Headers @{Authorization = "Bearer $token"} -Verbose -ContentType "application/json"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s