Extrait la liste des eMails reçu par un utilisateur dans exchange online.
Sommaire
Format du fichier d'entré :
user,AddressMail
User1.name,addressmail.user1@mondoamin.name
User2.name,addressmail.user2@mondoamin.name
User3.name,addressmail.user3@mondoamin.name
User4.name,addressmail.user4@mondoamin.name
Format du fichier de sortie :
Received,Status,SenderAddress,RecipientAddress,Subject
5/29/19 16:43,Delivered,contactXXX.externe@domaine.ext,addressmail.user1@mondoamin.name,ObjetMailXXX
5/29/19 16:40,FilteredAsSpam,contactXXX.externe@domaine.ext,addressmail.user1@mondoamin.name,ObjetMailXXX
5/31/19 13:39,FilteredAsSpam,contactXXX.externe@domaine.ext,addressmail.user1@mondoamin.name,ObjetMailXXX
5/31/19 10:58,Delivered,contactXXX.externe@domaine.ext,addressmail.user2@mondoamin.name,ObjetMailXXX
Script
Install-Module -Name AzureAD
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $session
$lst=@()
$Res=@()
#Entry format : user;addressMail
$FileImport=”C:\Temp\lstuser.txt”
#Export format : eMailTimeStamp;Status;SenderAddress;RecipientAddress;Subject
$FileExport=”C:\Temp\Result.csv”
#Import
$lst=Import-Csv $FileImport
foreach($user in $lst){
Write-Host “User : ” $user.addressMail
$lstmail=Get-MessageTrace -RecipientAddress $user.addressMail | Select-Object Received,Status,SenderAddress,RecipientAddress,Subject
foreach($mail in $lstmail){
$DataCollect = New-Object System.object
$DataCollect | Add-Member -name ‘TimeStamp’ -MemberType NoteProperty -Value $mail.Received
$DataCollect | Add-Member -name ‘Status’ -MemberType NoteProperty -Value $mail.Status
$DataCollect | Add-Member -name ‘SenderAddress’ -MemberType NoteProperty -Value $mail.SenderAddress
$DataCollect | Add-Member -name ‘RecipientAddress’ -MemberType NoteProperty -Value $mail.RecipientAddress
$DataCollect | Add-Member -name ‘Subject’ -MemberType NoteProperty -Value $mail.Subject
$Res+=$DataCollect
}
}
$Res | Export-Csv $FileExport