0% found this document useful (0 votes)
12 views2 pages

Import

The script retrieves mailbox statistics and Active Directory user information for all mailboxes in an Exchange environment. It compiles details such as display name, email address, title, department, office, telephone number, creation date, last logon time, and group memberships into a custom object. Finally, it exports this information to a CSV file on the user's desktop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Import

The script retrieves mailbox statistics and Active Directory user information for all mailboxes in an Exchange environment. It compiles details such as display name, email address, title, department, office, telephone number, creation date, last logon time, and group memberships into a custom object. Finally, it exports this information to a CSV file on the user's desktop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Import-Module ActiveDirectory

Get-Mailbox -ResultSize Unlimited | ForEach-Object {

$Mailbox = $_

try {

$Stats = Get-MailboxStatistics -Identity $Mailbox.Alias

$ADUser = Get-ADUser -Filter { UserPrincipalName -eq $Mailbox.UserPrincipalName } -


Properties whenCreated, LastLogonTimestamp, MemberOf, Title, Department, Office,
TelephoneNumber

if (-not $ADUser) {

Write-Warning "Aucun utilisateur trouvé avec l'adresse de messagerie $


($Mailbox.UserPrincipalName)"

return

$LastLogon = if ($Stats.LastLogonTime) {

$Stats.LastLogonTime

} elseif ($ADUser.LastLogonTimestamp) {

[DateTime]::FromFileTime($ADUser.LastLogonTimestamp)

} else {

"Jamais connecté"

$Groups = if ($ADUser.MemberOf) {

($ADUser.MemberOf | ForEach-Object {

($_ -split ',')[0] -replace '^CN='


}) -join ', '

} else {

"Aucun groupe"

[PSCustomObject]@{

Nom_Complet = $Mailbox.DisplayName

Adresse_Messagerie = $Mailbox.PrimarySmtpAddress

Titre = $ADUser.Title

Département = $ADUser.Department

Bureau = $ADUser.Office

Téléphone = $ADUser.TelephoneNumber

Date_Création = $ADUser.whenCreated

Dernière_Ouverture = $LastLogon

Groupes_AD = $Groups

} catch {

Write-Warning "Erreur avec $($Mailbox.DisplayName) : $_"

} | $Chemin = "$env:USERPROFILE\Desktop\Rapport_Utilisateurs_Exchange_AD.csv"

Export-Csv -Path $Chemin -NoTypeInformation -Encoding UTF8

You might also like