IAMinerva
HomeBlogAbout
m3M365 NewscoMicrosoft CopilotteMicrosoft TeamsshSharePoint & OneDriveinIntune & SecurityexExchange & OutlookpoPower PlatformazAzure & Entra IDtuTutorials & GuidesevEvents & ConferencesseSecuritywiWindows
IAMinerva

Professional blog dedicated to the Microsoft 365 ecosystem.

Quick links

HomeBlogAboutNewsletter

Stay informed

Get the latest Microsoft 365 news delivered straight to your inbox.

© 2026 IAMinerva. All rights reserved.

Built withNext.js&Tailwind
Trouver des Comptes Inactifs avec PowerShell
BlogM365 NewsFinding Inactive Accounts with PowerShell
M365 News#PowerShell#Inactive Accounts#Microsoft Graph SDK

Finding Inactive Accounts with PowerShell

Discover how to identify inactive accounts in Microsoft 365 using PowerShell and reduce costs of unused licenses.

Houssem MAKHLOUF
June 10, 2026
3 min read

TL;DR par Minerva

généré par IA

Discover how to identify inactive accounts in Microsoft 365 using PowerShell and reduce costs of unused licenses.

Introduction

Efficient management of Microsoft 365 licenses is essential for reducing costs and optimizing resources. Thanks to PowerShell and Microsoft Graph tools, it is possible to identify inactive user accounts and take action to recover unused licenses.

Why Identify Inactive Accounts?

The increase in Microsoft 365 license costs, scheduled for July 2026, is pushing IT professionals to review the use of assigned licenses. Identifying inactive accounts allows you to:

  • Reduce spending related to unused licenses.
  • Optimize budgets by replacing expensive licenses with cheaper alternatives.
  • Avoid management errors in license assignment (for example, licenses assigned to disabled accounts).
i

Good to Know

The Microsoft 365 Licensing Report script (version 1.96) can help you identify inactive accounts and analyze license usage in your environment.

Using PowerShell to Find Inactive Accounts

PowerShell, combined with the Microsoft Graph PowerShell SDK, offers a fast and flexible method to identify inactive user accounts. Here is a step-by-step guide:

1

Connect to Microsoft Graph

Sign in to Microsoft Graph with an administrator account and provide consent for the necessary permissions, including User.Read.All, Places.Read.All, and LicenseAssignment.Read.All.

⚡PowerShell
1Connect-MgGraph -Scopes "User.Read.All", "Places.Read.All", "LicenseAssignment.Read.All"
2

Retrieve Licensed Accounts

Run a PowerShell command to identify accounts with assigned licenses. This includes user accounts and room mailboxes.

⚡PowerShell
1[array]$Users = Get-MgUser -Filter "assignedLicenses/$count ne 0 and userType eq 'Member'" -Property Id, DisplayName, userPrincipalName, AssignedLicenses, SignInSessionsValidFromDateTime -All
2[array]$Places = Get-MgPlaceAsRoom -All -PageSize 500
3

Create a License Conversion Table

Generate a mapping table between license SKU identifiers and their names.

⚡PowerShell
1[array]$SKUs = Get-MgSubscribedSKU | Select-Object SkuId, SkuPartNumber
2$SKUHash = @{}
3ForEach ($SKU in $SKUs) {
4 $SKUHash.Add($SKU.SkuId, $SKU.SkuPartNumber)
5}
4

Identify Inactive Accounts

Define a cutoff date for inactive accounts (90 days) and identify users who have not signed in recently.

⚡PowerShell
1$CutoffDate = (Get-Date).AddDays(-90).ToUniversalTime()
2ForEach ($User in $Users) {
3 If (($User.SignInSessionsValidFromDateTime -lt $CutoffDate)) {
4 Write-Output "Inactive account: $User.DisplayName"
5 }
6}

Results and Actions

Once inactive accounts are identified, you can:

  • Replace expensive licenses with cheaper alternatives.
  • Remove licenses from unused accounts.
  • Analyze specific needs (example: extended leave or temporary interruptions).

alt

✦

Tip

Use the complete script available on GitHub Office 365 IT Pros to automate the process.

Conclusion

Optimizing the use of Microsoft 365 licenses through PowerShell and Microsoft Graph tools is a strategic approach for IT professionals. By quickly identifying inactive accounts, you can reduce costs and improve the efficiency of your M365 environment.

Related Articles

  • Removing Inactive Accounts with Entra ID Governance
  • Microsoft 365 Licensing Report v1.9
  • Analysis of M365 License Costs
Share:
HM

Houssem MAKHLOUF

Microsoft 365 enthusiast & IT professional.

Previous article

How to Resolve Active Directory Replication Errors

Jun 2, 2026
Next article

OneDrive without license: manage this hidden risk effectively

Jun 10, 2026

Related articles

Exécution de scripts PowerShell pour auditer des applications AI et gérer leurs enregistrements.copilot

Audit and Manage AI Applications with PowerShell

Audit unauthorized AI applications in Entra ID with PowerShell and Microsoft Graph to strengthen control and security.

Jun 28, 20264 min
Graphiques abstraits et géométriques avec des couches de couleurs translucides.exchange

Converting Exchange IDs for Microsoft 365 Graph API

Convert Exchange identifiers (storeId, entryId, RestId) for Graph API and targeted eDiscovery. Technical guide with complete PowerShell scripts.

Jun 28, 20267 min
Pyramide réfléchissante au centre de réseaux de fils dorés et cercles.azure

Graph Delta Queries for Entra ID Groups

Learn how to use Graph Delta Queries for Entra ID groups to track changes in real-time. Tutorials and scripts included.

Jun 27, 20264 min