pnp / cli-microsoft365

Manage Microsoft 365 and SharePoint Framework projects on any platform
https://aka.ms/cli-m365
MIT License
882 stars 312 forks source link

New command: Unused Mailboxes #5984

Open murati opened 2 months ago

murati commented 2 months ago

Usage

m365 outlook mail unused

Description

It retrieves the list of mailboxes which have no activity starting the given period

Options

Option Description

--period D7, D30, D90, D180 --since Starting date

Examples

Retrieve the list of inactive mailboxes in last 30 days

m365 outlook mail unused

Retrieve the list of active mailboxes starting the given date

m365 outlook mail unused --since 2024-01-01T00:00:000Z

Default properties

Additional Info

No response

waldekmastykarz commented 2 months ago

Thanks for the suggestion @murati! A couple of ideas:

@pnp/cli-for-microsoft-365-maintainers any other feedback before we open it up?

milanholemans commented 2 months ago

I'm curious if there's an API for this. If there isn't, this should probably be converted to a sample script in my opinion.

murati commented 2 months ago

Per my research, it requires EXO V3. That was actually my question. Graph does not directly support EXO but when I read the source code, I saw some endpoints apart from graph usage. Therefore, I thought, you could reach EXO beyond my knowledge.

We are building a smart admin panel for M365 and the EXO requiring modules are the slowest ones. Please let me know, if I can contribute somehow and further.

milanholemans commented 2 months ago

Can you provide some documentation about the API you want to leverage?

murati commented 2 months ago

Can you provide some documentation about the API you want to leverage?

This is how I execute this command:

Get-EXOMailbox -InactiveMailboxOnly

And here is the link : https://learn.microsoft.com/en-us/powershell/module/exchange/get-exomailbox?view=exchange-ps

I wasn't able to find further API documentation about it.

milanholemans commented 2 months ago

Let's see if we can get it to work.

MathijsVerbeeck commented 1 month ago

So, I've done a little bit of research, and the endpoint being called by the cmdlet Get-EXOMailbox is the following one: https://outlook.office365.com/adminapi/beta/{tenantid}/Mailbox?InactiveMailboxOnly=True

I have executed the cmdlet and also done some research regarding the permission scopes, however this one seems to use some permission scopes that I personally can't really place. The permission scopes being used are:

Also, it uses the application Microsoft Exchange REST API Based Powershell, which I'm not really able to find within my tenant it seems, not even in the Enterprise Applications.

So, in theory, we should be able to replicate this call but it looks to be quite hard.

murati commented 1 month ago

I wasnt aware of outlook adminapi. Would it be somehow possible to call https://admin.exchange.microsoft.com/beta/ ?

milanholemans commented 3 weeks ago

The difficulty is always finding documentation. Apart from that, the most challenging part will be fetching a valid access token, let's see if it's even possible to support this API.