PowerShell - 查找最早的电子邮件
PowerShell - Find Oldest Email
我被卡住了,我试图在一个人的邮箱中找到最早的“EMAIL”,但我不知道还能尝试什么。我想我需要在某处添加 ContainerClass -eq "IPF.Note",但我不确定在哪里。
以下脚本有效,但它找到了最旧的 ITEM,在我的例子中是 contact。我想分别查看每个容器(电子邮件、聊天、日历、联系人),但对于这个脚本,我只想知道最早的电子邮件。
谢谢
Get-MailboxFolderStatistics -IncludeOldestAndNewestItems -Identity USERID |
Where OldestItemReceivedDate -ne $null |
Sort OldestItemReceivedDate |
Select -First 1 OldestItemReceivedDate
假设这是出于合规性原因在 Exchange 服务器上搜索邮箱中的项目,您应该使用 Search-Mailbox cmdlet - https://docs.microsoft.com/en-us/powershell/module/exchange/search-mailbox?view=exchange-ps
要使 Exchange Online 在邮箱中搜索项目,您应该使用 New-ComplianceSearch cmdlet https://docs.microsoft.com/en-us/powershell/module/exchange/new-compliancesearch?view=exchange-ps
此网页显示了如何按日期搜索 - New-ComplianceSearch:如何使用较新版本的 Search-Mailbox https://www.codetwo.com/admins-blog/new-compliancesearch-new-version-of-search-mailbox/
此网页有一个搜索邮箱的脚本,包括日期 PowerShell – New-ComplianceSearch 脚本,用于遍历所有邮箱,找到目标邮件并将其删除 - https://365basics.com/powershell-new-compliancesearch-script-to-go-through-all-mailboxes-find-a-target-message-and-remove-it/
按照你原来的方法,应该是这样的。假设您有适当的权限。
Get-MailboxFolderStatistics -ID <mailboxemailaddress> -IncludeOldestAndNewestItems | select Identity, Name, FolderPath, ItemsInFolder, FolderSize, OldestItemReceivedDate | Export-Csv C:\temp\Mailbox.csv -NoTypeInformation
您可以按商品类型过滤您拥有的商品,但我会在获得统计信息后进行过滤,因此您只需查询一次交换:
# Get the folder statistics for all folders
$stats = Get-MailboxFolderStatistics -IncludeOldestAndNewestItems -Identity $USERID
# Get the oldest email. Can re-use $stats for the other item types
$OldestEmail = $stats |
Where-Object {$_.OldestItemReceivedDate -and $_.ContainerClass -eq 'IPF.Note'} |
Sort-Object OldestItemReceivedDate |
Select-Object ContainerClass,OldestItemReceivedDate,FolderPath -First 1
# Outputs
ContainerClass OldestItemReceivedDate FolderPath
-------------- ---------------------- ----------
IPF.Note 2/8/2016 2:07:50 PM /Inbox
邮箱文件夹统计命令不搜索可恢复项目的说法是正确的by default。它也 不搜索邮箱存档,除非您指定-Archive
。如果您需要这些,则必须进行额外的搜索:
# Get recoverable items:
Get-MailboxFolderStatistics -Identity $USERID -FolderScope 'RecoverableItems' -IncludeOldestAndNewestItems |
Where-Object OldestItemReceivedDate |
Sort-Object OldestItemReceivedDate |
Select-Object ContainerClass,OldestItemReceivedDate,FolderPath -First 1
# Note that deleted item containers do not have an item type!
ContainerClass OldestItemReceivedDate FolderPath
-------------- ---------------------- ----------
2/5/2016 3:41:33 PM /Deletions
我被卡住了,我试图在一个人的邮箱中找到最早的“EMAIL”,但我不知道还能尝试什么。我想我需要在某处添加 ContainerClass -eq "IPF.Note",但我不确定在哪里。
以下脚本有效,但它找到了最旧的 ITEM,在我的例子中是 contact。我想分别查看每个容器(电子邮件、聊天、日历、联系人),但对于这个脚本,我只想知道最早的电子邮件。
谢谢
Get-MailboxFolderStatistics -IncludeOldestAndNewestItems -Identity USERID |
Where OldestItemReceivedDate -ne $null |
Sort OldestItemReceivedDate |
Select -First 1 OldestItemReceivedDate
假设这是出于合规性原因在 Exchange 服务器上搜索邮箱中的项目,您应该使用 Search-Mailbox cmdlet - https://docs.microsoft.com/en-us/powershell/module/exchange/search-mailbox?view=exchange-ps
要使 Exchange Online 在邮箱中搜索项目,您应该使用 New-ComplianceSearch cmdlet https://docs.microsoft.com/en-us/powershell/module/exchange/new-compliancesearch?view=exchange-ps
此网页显示了如何按日期搜索 - New-ComplianceSearch:如何使用较新版本的 Search-Mailbox https://www.codetwo.com/admins-blog/new-compliancesearch-new-version-of-search-mailbox/
此网页有一个搜索邮箱的脚本,包括日期 PowerShell – New-ComplianceSearch 脚本,用于遍历所有邮箱,找到目标邮件并将其删除 - https://365basics.com/powershell-new-compliancesearch-script-to-go-through-all-mailboxes-find-a-target-message-and-remove-it/
按照你原来的方法,应该是这样的。假设您有适当的权限。
Get-MailboxFolderStatistics -ID <mailboxemailaddress> -IncludeOldestAndNewestItems | select Identity, Name, FolderPath, ItemsInFolder, FolderSize, OldestItemReceivedDate | Export-Csv C:\temp\Mailbox.csv -NoTypeInformation
您可以按商品类型过滤您拥有的商品,但我会在获得统计信息后进行过滤,因此您只需查询一次交换:
# Get the folder statistics for all folders
$stats = Get-MailboxFolderStatistics -IncludeOldestAndNewestItems -Identity $USERID
# Get the oldest email. Can re-use $stats for the other item types
$OldestEmail = $stats |
Where-Object {$_.OldestItemReceivedDate -and $_.ContainerClass -eq 'IPF.Note'} |
Sort-Object OldestItemReceivedDate |
Select-Object ContainerClass,OldestItemReceivedDate,FolderPath -First 1
# Outputs
ContainerClass OldestItemReceivedDate FolderPath
-------------- ---------------------- ----------
IPF.Note 2/8/2016 2:07:50 PM /Inbox
邮箱文件夹统计命令不搜索可恢复项目的说法是正确的by default。它也 不搜索邮箱存档,除非您指定-Archive
。如果您需要这些,则必须进行额外的搜索:
# Get recoverable items:
Get-MailboxFolderStatistics -Identity $USERID -FolderScope 'RecoverableItems' -IncludeOldestAndNewestItems |
Where-Object OldestItemReceivedDate |
Sort-Object OldestItemReceivedDate |
Select-Object ContainerClass,OldestItemReceivedDate,FolderPath -First 1
# Note that deleted item containers do not have an item type!
ContainerClass OldestItemReceivedDate FolderPath
-------------- ---------------------- ----------
2/5/2016 3:41:33 PM /Deletions