Get-MgmtGraphUserMailFolder
MgmtGraph: Audits user mail folders
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Mail
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
[string]$Identity,
[string]$MailFolderId
)
Process {
try {
$params = @{
'UserId' = $Identity
'ErrorAction' = 'Stop'
}
if ($MailFolderId) {
$params.Add('MailFolderId', $MailFolderId)
}
else {
$params.Add('All', $true)
}
$folders = Get-MgUserMailFolder @params
$results = foreach ($f in $folders) {
[PSCustomObject]@{
DisplayName = $f.DisplayName
Id = $f.Id
ChildFolderCount = $f.ChildFolderCount
TotalItemCount = $f.TotalItemCount
UnreadItemCount = $f.UnreadItemCount
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
}
Write-Output ($results | Sort-Object DisplayName)
}
catch {
throw
}
}Specifies the UserPrincipalName or ID of the user.
Optional. Specifies the ID of a specific mail folder to retrieve. If omitted, all root folders are listed.