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 MBforeach($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 GreenRemove-PSSession $Session
Vous pouvez utiliser ce script et l’adapter selon vos propres besoins.
Fabrice Romelard
Sources utilisées:
- http://www.cloudpartner.fi/?p=350
- https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/get-mailboxstatistics?view=exc...
- https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/get-mailbox?view=exchange-ps
- https://support.citrix.com/article/CTX229565
- http://www.vdberge.com/kennisbank/office-365-error-the-term-get-mailbox-is-not-recognized/
- https://4sysops.com/archives/sort-exchange-and-office-365-mailboxes-by-size-with-powershell/
Version Anglaise:
Commentaires
Enregistrer un commentaire