get user login reports in office 365

Francesco Falanga 40 Punti di reputazione
2025-02-19T15:50:34.7033333+00:00

hello everyone.

and thanks in advance to anyone who can give me advice.

i need to export a list of users who haven't logged in for more than a month with their account.is there a script that i could run in powershell?

Exchange | Exchange Server | Altro
Exchange | Exchange Server | Altro

Una piattaforma stabile di e-mail, calendario e collaborazione sviluppata da Microsoft, progettata per comunicazione e gestione dei dati di livello enterprise.Argomenti vari che non rientrano in categorie specifiche.

Microsoft 365 e Office | Installare, riscattare, attivare | Per il lavoro | Windows
0 commenti Nessun commento

Risposta accettata dall'autore della domanda
Anonimo
2025-02-20T02:33:58.8666667+00:00

Hi @francesco falanga

Welcome to the Microsoft Q&A platform!
I will be using a user who has not logged in for 7 days as an example, you can try the following script:

$cutoffDate = (Get-Date).AddDays(-30)
$mailboxes = Get-Mailbox -ResultSize Unlimited
$inactiveUsers = @()
foreach ($mailbox in $mailboxes) {
    $lastLogonTime = (Get-MailboxStatistics -Identity $mailbox.Alias).LastLogonTime
    if ($lastLogonTime -lt $cutoffDate) {
        $userInfo = New-Object PSObject -Property @{
            DisplayName = $mailbox.DisplayName
            UserPrincipalName = $mailbox.UserPrincipalName
            LastLogonTime = $lastLogonTime
        }
        $inactiveUsers += $userInfo
    }
}
$inactiveUsers | Export-Csv -Path "C:\InactiveUsers.csv" -NoTypeInformation
Write-Output "succeed:C:\InactiveUsers.csv"

Immagine dell'utente


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

La risposta è stata utile?

0 commenti Nessun commento

1 risposta aggiuntiva

Ordina per: Più utili
  1. Francesco Falanga 40 Punti di reputazione
    2025-02-20T15:59:12.1633333+00:00

    Tianyi Chang

    thank you so much for the prompt reply. I will try the script you kindly sent me and let you know. I need to see 30 days and not seven as you mentioned

    La risposta è stata utile?


Risposta

Le risposte possono essere contrassegnate come "Accettata" dall'autore della domanda e "Consigliata" dai moderatori, in modo da consentire agli utenti di sapere che la risposta ha risolto il problema dell'autore.