Skip to main content

Clean up stale Entra B2B guest accounts with Microsoft Graph, Teams, and SharePoint

Workflow preview

Workflow preview
100%
Clean up stale Entra B2B guest accounts with Microsoft Graph, Teams, and SharePoint preview
Open on n8n.io

1. Workflow Overview

Quick overview This workflow runs weekly to find inactive Entra ID (Azure AD) B2B guest accounts using Microsoft Graph sign in activity, notifies each guest’s sponsor via Microsoft Teams, waits 72 ...

Best for

  • Engineering automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.stickynote, n8n-nodes-base.scheduletrigger, n8n-nodes-base.set, n8n-nodes-base.code, n8n-nodes-base.httprequest, n8n-nodes-base.if, n8n-nodes-base.microsoftteams, n8n-nodes-base.splitinbatches

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Mychel Garzon.

Original n8n.io source

1.1 Workflow description

Title
Clean up stale Entra B2B guest accounts with Microsoft Graph, Teams, and SharePoint
Workflow name
Clean up stale Entra B2B guest accounts with Microsoft Graph, Teams, and SharePoint

Quick overview

This workflow runs weekly to find inactive Entra ID (Azure AD) B2B guest accounts using Microsoft Graph sign-in activity, notifies each guest’s sponsor via Microsoft Teams, waits 72 hours, deletes the accounts, and logs successful deletions to a SharePoint list.

How it works

  1. Runs every Monday at 08:00 (server time) on a scheduled trigger.
  2. Fetches all Entra ID guest users from Microsoft Graph (with pagination) including signInActivity metadata.
  3. Filters guests whose last sign-in (or creation date if they never signed in) is older than the configured inactivity threshold.
  4. If no stale guests are found, posts a completion message to a Microsoft Teams channel and stops.
  5. For each stale guest, looks up the guest’s manager in Microsoft Graph and posts a deletion notice to a Microsoft Teams channel tagging the sponsor details.
  6. Waits 72 hours, then deletes the stale guest account via Microsoft Graph.
  7. If deletion succeeds, writes an audit record to a SharePoint list; if deletion fails, posts an error alert to Microsoft Teams and continues with the next guest.
  8. Posts a final “run complete” summary to Microsoft Teams after all stale guests are processed.

Setup

  1. Create a Microsoft Graph OAuth2 credential in n8n with permissions to read users and sign-in activity, read user manager, delete users, and write to the target SharePoint list.
  2. Create or choose a SharePoint site and list for audit logging, ensure the list has fields like GuestEmail, DisplayName, LastSignIn, SponsorNotified, DeletedAt, and DeletedBy, then set the SharePoint site ID and list ID in the Config values.
  3. Add Microsoft Teams credentials (or ensure Graph-backed Teams access) and set the Team ID and Channel ID in the Config values for where notifications and summaries are posted.
  4. Adjust the inactivity threshold (days) and response window (hours) in the Config values to match your governance policy and confirm the workflow timezone matches your intended schedule.

Requirements

  • Microsoft Entra ID app registration with the following application permissions granted and admin consent applied: User.Read.All, AuditLog.Read.All, User.ReadWrite.All, Directory.Read.All, Sites.ReadWrite.All
  • Two credentials configured in n8n: a Generic OAuth2 credential using Client Credentials flow for Microsoft Graph API calls, and a Microsoft Teams OAuth2 credential for Teams notifications
  • A SharePoint list named GuestAccountAuditLog with columns: GuestEmail, DisplayName, LastSignIn, SponsorNotified, DeletedAt, DeletedBy

Customization

  • Update the Config node with your SharePoint site ID, SharePoint list ID, Teams team ID, and Teams channel ID before activating
  • Edit the Teams notification message in the Send Notification to Sponsor node to match your organization's tone and include any required policy references
  • Replace the static channel destination with a dynamic lookup if your organization routes notifications to different channels per department or business unit
  • To add human approval instead of time-based deletion, configure the Wait node to resume via webhook and build a companion workflow that calls the n8n resume endpoint when a sponsor responds

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 2 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 3 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 4 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 6 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 8 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note8

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note9

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note10

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Sticky Note11

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - Weekly Trigger at 8am Monday

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.2

Block 14 - Set Config Parameters

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 15 - Initialize Pagination Loop

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 16 - Fetch Guest Page via URL

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 17 - Accumulate Guests from Page

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 18 - If More Pages Available

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 19 - Set Next URL

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 20 - Filter Stale Guest Accounts

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 21 - Check Stale Guests Presence

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 22 - Notify No Stale Guests

Type / Role
n8n-nodes-base.microsoftTeams - microsoftTeams
Config choices
Version 2

Block 23 - Unpack Stale Guests Array

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 24 - Loop Over Stale Guests

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Showing the first 24 of 36 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Clean up stale Entra B2B guest accounts with Microsoft Graph, Teams, and SharePoint
Complexity advanced
Nodes 36
Categories Engineering
Author Mychel Garzon
Published 04 Jun 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/16118/16118.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Clean up stale Entra B2B guest accounts with Microsoft Graph, Teams, and SharePoint do?

Quick overview This workflow runs weekly to find inactive Entra ID (Azure AD) B2B guest accounts using Microsoft Graph sign in activity, notifies each guest’s sponsor via Microsoft Teams, waits 72 ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering use case.