1

用户的已删除项目中有超过 40 GB 的电子邮件。她已经确认她不需要它们来恢复。

我已经使用此处概述的方法进行了搜索以提取她已删除的项目文件夹 ID

https://docs.microsoft.com/en-us/microsoft-365/compliance/use-content-search-for-targeted-collections?view=o365-worldwide

然后,我在合规中心为她的用户创建了一个搜索,使用文件夹 id 作为搜索词,在 2020 年 3 月 30 日之前进行搜索。搜索返回 20+ GB 的结果

我使用 Connect-IPPSSession 通过 2fa 连接到合规服务并运行以下命令

New-ComplianceSearchAction -SearchName“2020 年 3 月 30 日之前删除的项目”-Purge -PurgeType HardDelete

动作完成瞬间显示

结果:清除类型:HardDelete;项目数:0;总大小 0;细节: {}

用户邮箱根本没有缩小,所有删除的项目都还在。再次运行搜索返回相同的 20+ GB 结果

我已经尝试了软删除和硬删除选项的操作,结果是一样的,没有任何反应。

我已通过 Get-ComplianceSearch 确认,该搜索名称在 powershell 中显示了估计的 20GB 数据,那么为什么 HardDelete 没有删除任何内容?

4

1 回答 1

2

所以我了解到一个 Purge 操作一次只能删除 10 个项目。至于为什么你和我没有看到任何电子邮件被删除,我从来没有完全弄清楚。我怀疑它在每次运行时都会删除 10 个,但由于我正在搜索多个邮箱(根据我的要求),结果并不清楚。从那以后,我通过使用一个脚本(如下)成功地获得了成功,我根据我通过这篇博客文章找到的一个脚本对我的要求进行了调整。

非常感谢托尼·雷德蒙德(Tony Redmond)我修改了他的剧本……

Clear-Host

# Connect to Exchange Online
$credentials = get-credential;
Connect-ExchangeOnline -Credential $credentials
$SccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credentials -Authentication "Basic" -AllowRedirection;
Import-PSSession $SccSession

$mailboxes = @("mailbox1@example.net", "mailbox2@example.net")

$monthsToKeep = 3

$sourceDate = (Get-Date).AddMonths(-$monthsToKeep)

$searchName = "PurgeEmails"

$contentQuery = "received<=$($sourcDeate) AND kind:email"

# Clean-up any old searches from failed runs of this script
if (Get-ComplianceSearch -Identity $searchName) {
    Write-Host "Cleaning up any old searches from failed runs of this script"

    try {
        Remove-ComplianceSearch -Identity $searchName -Confirm:$false | Out-Null
    }
    catch {
        Write-Host "Clean-up of old script runs failed!" -ForegroundColor Red
        break
    }
}

Write-Host "Creating new search for emails older than $($sourceate)"

New-ComplianceSearch -Name $searchName -ContentMatchQuery $contentQuery -ExchangeLocation $mailboxes -AllowNotFoundExchangeLocationsEnabled $true | Out-Null
                                                                            
Start-ComplianceSearch -Identity $searchName | Out-Null

Write-Host "Searching..."

while ((Get-ComplianceSearch -Identity $searchName).Status -ne "Completed") {
    Write-Host "." -NoNewline
    Start-Sleep -Seconds 2
}

$items = (Get-ComplianceSearch -Identity $searchName).Items

if ($items -gt 0) {
    $searchStatistics = Get-ComplianceSearch -Identity $searchName | Select-Object -Expand SearchStatistics | Convertfrom-JSON

    $sources = $searchStatistics.ExchangeBinding.Sources | Where-Object { $_.ContentItems -gt 0 }

    Write-Host ""
    Write-Host "Total Items found matching query:" $items 
    Write-Host ""
    Write-Host "Items found in the following mailboxes"
    Write-Host "--------------------------------------"

    foreach ($source in $sources) {
        Write-Host $source.Name "has" $source.ContentItems "items of size" $source.ContentSize
    }

    Write-Host ""

    $iterations = 0;
    
    $itemsProcessed = 0
    
    while ($itemsProcessed -lt $items) {
        $iterations++

        Write-Host "Deleting items iteration $($iterations)"

        New-ComplianceSearchAction -SearchName $searchName -Purge -PurgeType HardDelete -Confirm:$false | Out-Null

        while ((Get-ComplianceSearchAction -Identity "$($searchName)_Purge").Status -ne "Completed") { 
            Start-Sleep -Seconds 2
        }

        $itemsProcessed = $itemsProcessed + 10
        
        # Remove the search action so we can recreate it
        Remove-ComplianceSearchAction -Identity "$($searchName)_Purge" -Confirm:$false  
    }
} else {
    Write-Host "No items found"
}

Write-Host ""
Write-Host "COMPLETED!"
于 2020-07-28T12:09:01.003 回答