【问题标题】:Exclude recoverable items folder from New-ComplianceSearch从 New-ComplianceSearch 中排除可恢复的项目文件夹
【发布时间】:2020-06-23 21:19:14
【问题描述】:

我正在使用 Office 365 的安全与合规中心执行合规搜索并使用软删除删除违规电子邮件。完成后,我执行相同的搜索以确认电子邮件已被删除,但我的搜索查询看到相同数量的结果。这是因为软删除会将电子邮件移动到“可恢复项目”文件夹。我的问题是,如何在排除“可恢复项目”文件夹的同时创建New-ComplianceSearch

更新 马修为我指出了下面正确的方向。使用脚本 here(及以下),您可以获得指定邮箱的删除、可恢复项目和清除文件夹的文件夹 ID:

# Collect the target email address
$addressOrSite = Read-Host "Enter an email address"

# Authenticate with Exchange Online and the Security & Complaince Center (Exchange Online Protection - EOP)
if (!$credentials)
{
    $credentials = Get-Credential
}

if ($addressOrSite.IndexOf("@") -ige 0)
{
    # List the folder Ids for the target mailbox
    $emailAddress = $addressOrSite

    # Authenticate with Exchange Online
    if (!$ExoSession)
    {
        $ExoSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid/ -Credential $credentials -Authentication Basic -AllowRedirection
        Import-PSSession $ExoSession -AllowClobber -DisableNameChecking
    }

    $folderQueries = @()
    $folderStatistics = Get-MailboxFolderStatistics $emailAddress
    foreach ($folderStatistic in $folderStatistics)
    {
        $folderId = $folderStatistic.FolderId;
        $folderPath = $folderStatistic.FolderPath;

        $encoding= [System.Text.Encoding]::GetEncoding("us-ascii")
        $nibbler= $encoding.GetBytes("0123456789ABCDEF");
        $folderIdBytes = [Convert]::FromBase64String($folderId);
        $indexIdBytes = New-Object byte[] 48;
        $indexIdIdx=0;
        $folderIdBytes | select -skip 23 -First 24 | %{$indexIdBytes[$indexIdIdx++]=$nibbler[$_ -shr 4];$indexIdBytes[$indexIdIdx++]=$nibbler[$_ -band 0xF]}
        $folderQuery = "folderid:$($encoding.GetString($indexIdBytes))";

        $folderStat = New-Object PSObject
        Add-Member -InputObject $folderStat -MemberType NoteProperty -Name FolderPath -Value $folderPath
        Add-Member -InputObject $folderStat -MemberType NoteProperty -Name FolderQuery -Value $folderQuery

        $folderQueries += $folderStat
    }
    Write-Host "-----Exchange Folders-----"
    $folderQueries |ft
}

然后,您可以使用这些 FolderID 从搜索中删除文件夹。例如:

New-ComplianceSearch -Name test123 -ExchangeLocation user@mycompany.com -ContentMatchQuery "subject:'some subject' AND NOT ((folderid:3F4BE1AEF6C6BB45B8F8EEFE472A7E5C0000000001130000) OR (folderid:3F4BE1AEF6C6BB45B8F8EEFE472A7E5C0000000001140000) OR (folderid:3F4BE1AEF6C6BB45B8F8EEFE472A7E5C0000000001160000))"

【问题讨论】:

    标签: powershell office365


    【解决方案1】:

    从安全与合规中心排除文件夹的关键是 FolderID 属性。您可以在此站点上找到有关此属性和其他属性的文档:

    https://support.office.com/en-us/article/Keyword-queries-and-search-conditions-for-Content-Search-c4639c2e-7223-4302-8e0d-b6e10f1c3be3?ui=en-US&rs=en-US&ad=US

    如果您在该链接中搜索 FolderID,您将找到另一个指向文档的链接,该链接介绍了如何获取特定邮箱的 FolderID,包括执行此操作的 PowerShell 代码。该链接是:

    https://support.office.com/en-us/article/Use-Content-Search-in-Office-365-for-targeted-collections-e3cbc79c-5e97-43d3-8371-9fbc398cd92e?ui=en-US&rs=en-US&ad=US#step1

    您正在尝试做的,排除可恢复项目,实际上涉及排除四个单独的文件夹:

    /Recoverable Items
    /Deletions
    /Purges
    /Versions
    

    每个文件夹都有一个关联的 FolderID。以上面第二个链接中的值为例...

    /Recoverable Items  folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001140000
    /Deletions          folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001150000
    /Purges             folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001170000
    /Versions           folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001160000
    

    ...您可以在关键字搜索中添加类似内容以排除这些文件夹:

    NOT ((folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001140000) OR (folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001150000) OR (folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001170000) OR (folderid:FDB58AF45BAF2F4A8CFD98F5396C6EB0000000001160000))
    

    当然,您必须从要为其执行此操作的每个邮箱中检索这四个文件夹的实际值。另请注意,排除文件夹排除其子文件夹...您需要为每个文件夹和每个要作为排除或包含目标的子文件夹使用 FolderID 值。

    希望这会有所帮助!

    【讨论】:

    • 谢谢,这听起来很有希望。我会尽快研究它,并希望能提出一些建议,尽管这听起来需要一些工作。如果你很好奇,我正在制作一个 PowerShell 脚本来删除 O365 租户中每个邮箱中的垃圾邮件和恶意电子邮件:github.com/jdgregson/Delete-Emails-O365/blob/master/…。到目前为止它非常有效,但存在无法确认电子邮件已移动到已删除项目文件夹的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 2018-06-04
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    相关资源
    最近更新 更多