Accéder au contenu principal

Office 365: Script PowerShell pour auditer l’usage d’Exchange Online de votre tenant

 Dans la suite des précédents articles pour auditer un Tenant Office 365, voici un script dédié à l’utilisation du moteur Exchange Online.

Ce script permet de générer un simple fichier CSV utilisable dans Excel.


[string]$username = "Admin@yourtenant.onmicrosoft.com"
[string]$PwdTXTPath = "C:\SECUREDPWD\ExportedPWD-$($username).txt"

$secureStringPwd = ConvertTo-SecureString -string (Get-Content $PwdTXTPath)
$adminCreds = New-Object System.Management.Automation.PSCredential $username, $secureStringPwd

#$adminCreds = get-credential

$ReportPath = "C:\EXCHANGE\Reports\"
$data = @()

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-LiveID/ -Credential $adminCreds -Authentication Basic -AllowRedirection
Import-PSSession $Session

$MbxUsers = get-mailbox -resultsize unlimited
#$MbxUsers = get-mailbox  # < for testing only first 1000 mailbox
#$MbxUsers = get-mailbox -RecipientTypeDetails SharedMailbox -resultsize 50 # < for testing only first 50 shared MB

foreach($user in $mbxusers)
{
    $UPN = $user.userprincipalname
    $Mbx = Get-MailboxStatistics $UPN
    $TotalMBSize = [math]::Round((($Mbx.TotalItemSize.Value.ToString()).Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2) #"69.48 MB (72,854,427 bytes)"

    Write-host " >> MailBox UPN:", $user.userprincipalname, "- MailBoxType:", $user.RecipientTypeDetails, "- Mailbox ItemNumber:", $Mbx.ItemCount -ForegroundColor Magenta
    Write-host "    >> MailBox Size Text:", $Mbx.TotalItemSize ," - MailBox SizeMB:", $TotalMBSize
    Write-host "    >> ProhibitSendQuota:", $user.ProhibitSendQuota, "- ProhibitSendReceiveQuota:", $user.ProhibitSendReceiveQuota
   
    $Properties = @{
        Logoff = $Mbx.lastlogofftime
        Logon = $Mbx.lastlogontime
        IsEncrypted = $Mbx.IsEncrypted
         ProhibitSendReceiveQuotaMB = $user.ProhibitSendReceiveQuota
        ProhibitSendQuotaMB = $user.ProhibitSendQuota
        TotalSizeMB = $TotalMBSize.ToString()
        ItemCount = $Mbx.ItemCount
        IsArchiveMailbox = $Mbx.IsArchiveMailbox
         RecipientTypeDetails = $user.RecipientTypeDetails
        Alias = $user.alias
        UPN = $user.userprincipalname
         Displayname = $Mbx.Displayname
        Name = $user.name
         }
    $data += New-Object psobject -Property $properties
}
 
$datestring = (get-date).ToString("yyyyMMdd-hhmm")
$fileName = Join-Path -Path $ReportPath  -ChildPath $("ExchangeMailbox_"+ $datestring + ".csv")
   
Write-host " -----------------------------------------" -ForegroundColor Green
Write-Host (" >>> writing to file {0}" -f $fileName) -ForegroundColor Green
$data | Select-Object Name,D isplayname, UPN, Alias, RecipientTypeDetails, IsArchiveMailbox, IsEncrypted, ItemCount, TotalSizeMB,ProhibitSendQuotaMB, ProhibitSendReceiveQuotaMB, Logon, Logoff | Export-csv $fileName -NoTypeInformation -enc utf8
Write-host " -----------------------------------------" -ForegroundColor Green

Remove-PSSession $Session


Vous pouvez utiliser ce script et l’adapter selon vos propres besoins.

Fabrice Romelard

Sources utilisées:

Version Anglaise:

Commentaires

Posts les plus consultés de ce blog

Série de Videos sur Home Assistant intégrant la production Photovoltaïque

 Un certain nombre de vidéos sont en ligne pour intégrer sa production photovoltaïque dans Home Assistant en partant de la base. Installation de Home Assistant: On peut ensuite intégrer les composant des Micro-Onduleurs Enphase, mais aussi les batteries Enphase: Ou encore le composant de contrôle Ecojoko: Ce qui permet alors de faire des comparaisons entre les valeurs capturées: Des videos seront encore publiés dans les prochaines semaines sur différents aspects de cette solution. Fab

Nouveau Scripts PowerShell publiés pour gérer les Storage Accounts dans Azure Cloud

Deux scripts sont en lignes pour nettoyer des Storage Account dans Azure Cloud: Supprimer les Blobs d'un container existant https://techcommunity.microsoft.com/discussions/azure/powershell-script-to-remove-all-blobs-from-storage-account/4357815 ------------------------------------------------------- [string]$myConnectionString = "DefaultEndpointsProtocol=https;AccountName=YourStorageAccountName;AccountKey=YourKeyFromStorageAccountConnectionString;EndpointSuffix=core.windows.net" [string]$ContainerName = "YourBlobContainerName" [int]$blobCountAfter = 0 [int]$blobCountBefore = 0 $context = New-AzStorageContext -ConnectionString $myConnectionString $blobCountBefore = (Get-AzStorageBlob -Container $ContainerName -Context $context).Count Write-Host "Total number of blobs in the container Before deletion: $blobCount" -ForegroundColor Yellow Get-AzStorageBlob -Container $ContainerName -Context $context | ForEach-Object {     $_ | Remove-AzureStorageBlob   # o...

Série de vidéos sur le montage d'une serre horticole ACD

 Episode 1: Préparation du terrain Episode 2: Montage de la serre en elle même Episode 3: Finalisation avec le montage électrique alimentant la serre Bon visionnage Fab