Skip to main content

Optimize inactive Microsoft 365 premium licenses with Graph and Teams

Workflow preview

Workflow preview
100%
Optimize inactive Microsoft 365 premium licenses with Graph and Teams preview
Open on n8n.io

1. Workflow Overview

Quick overview This workflow runs monthly to audit Microsoft 365 licensing via Microsoft Graph, identifies inactive users holding premium SKUs (excluding an exemption group and recent hires), optio...

Best for

  • CRM 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.itemlists, n8n-nodes-base.if, n8n-nodes-base.microsoftteams

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
Optimize inactive Microsoft 365 premium licenses with Graph and Teams
Workflow name
Optimize inactive Microsoft 365 premium licenses with Graph and Teams

Quick overview

This workflow runs monthly to audit Microsoft 365 licensing via Microsoft Graph, identifies inactive users holding premium SKUs (excluding an exemption group and recent hires), optionally downgrades them to a baseline license, and posts a results summary to a Microsoft Teams channel.

How it works

  1. Runs on a monthly cron schedule at 06:00 on the 1st of each month.
  2. Loads and validates configuration values (premium SKU part numbers, baseline SKU ID, inactivity/new-hire windows, exemption group ID, Teams destination, and dry-run mode).
  3. Calls Microsoft Graph to list subscribed SKUs and builds a list of premium SKU IDs to target.
  4. Retrieves members of a Microsoft Entra ID (Azure AD) security group to exclude them from license changes.
  5. Fetches all enabled member users with assigned licenses from Microsoft Graph and filters for users who hold a premium SKU and have been inactive beyond the threshold (treating no sign-in history as inactive except for recent hires).
  6. If no users qualify, posts a “no action required” audit message to the configured Microsoft Teams channel.
  7. If users qualify, processes them in batches with a short wait between calls and either performs a dry run or uses Microsoft Graph assignLicense to remove premium licenses and add the baseline SKU per user.
  8. Posts Microsoft Teams error alerts for failed license operations and sends a final Microsoft Teams summary listing the successfully processed accounts.

Setup

  1. Create a Microsoft Graph OAuth2 credential in n8n with permissions to read users and groups and to update user license assignments.
  2. Update the Config values for baselineSkuId, exemptionGroupId, teamsTeamId, teamsChannelId, and (optionally) premiumSkuPartNumbers and the inactivity/new-hire thresholds.
  3. Ensure the exemption group exists in Microsoft Entra ID and contains any users who must never be downgraded.
  4. Connect Microsoft Teams credentials in n8n and verify the workflow can post to the target team and channel.
  5. Set dryRunMode to true for testing, then disable it to allow live license changes.

Requirements

  • Microsoft 365 tenant with Azure AD Premium P1 or P2 (required for signInActivity data)
  • App Registration in Entra ID with admin-consented application permissions: User.Read.All, AuditLog.Read.All, User.ReadWrite.All, Organization.Read.All, Directory.Read.All, GroupMember.Read.All
  • Microsoft Graph OAuth2 credential configured in n8n and selected on the Fetch All Licensed Users node
  • Microsoft Teams credential configured in n8n with access to the target team and channel
  • An Entra ID Security Group populated with any accounts that should never be downgraded (break-glass, service accounts, executives)
  • The skuId of your target baseline license plan (retrieve it by calling GET https://graph.microsoft.com/v1.0/subscribedSkus)

Customization

  • Adjust the cron expression on Monthly Schedule Trigger at 6am to match your preferred schedule and UTC offset.
  • Update the Teams message templates in Notify No Downgrades Required, Alert License Error, and Deliver Summary to IT Manager to match your organization's tone and formatting standards.

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 - Monthly Schedule Trigger at 6am

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

Block 12 - Set Configuration Parameters

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

Block 13 - Validate Configuration

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

Block 14 - Fetch Subscribed SKUs

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

Block 15 - Generate Premium SKU Map

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

Block 16 - Retrieve Exemption Group Members

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

Block 17 - Compile Exemption List

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

Block 18 - Fetch All Licensed Users

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

Block 19 - Filter Inactive Premium Members

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

Block 20 - Check Downgradable Users

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

Block 21 - Notify No Downgrades Required

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

Block 22 - Complete No Action Needed

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

Block 23 - Divide Downgrade Plan

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

Block 24 - Batch Process Downgrades

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 Optimize inactive Microsoft 365 premium licenses with Graph and Teams
Complexity advanced
Nodes 36
Categories CRM
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/16110/16110.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 Optimize inactive Microsoft 365 premium licenses with Graph and Teams do?

Quick overview This workflow runs monthly to audit Microsoft 365 licensing via Microsoft Graph, identifies inactive users holding premium SKUs (excluding an exemption group and recent hires), optio...

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 CRM use case.