搜索指定网站内容( DocumentLink属性比Path属性更可靠,你知道吗?(组图))
优采云 发布时间: 2022-04-14 01:30搜索指定网站内容(
DocumentLink属性比Path属性更可靠,你知道吗?(组图))
在目标集合上使用内容搜索
谢谢。
本文内容
内容搜索工具直接在 Microsoft 365 合规中心 UI 中搜索 Exchange 邮箱或 SharePoint 和 OneDrive for Business 文件夹。但是,可以通过在实际搜索查询语法中为 网站 指定电子邮件的文件夹 ID 属性或路径 (DocumentLink) 属性来搜索特定文件夹(称为目标集合)。当您确信响应案例或特权项目的项目位于特定邮箱或 网站 文件夹中时,使用内容搜索执行目标集合很有用。您可以使用本文中的脚本获取邮箱文件夹的文件夹 ID 或 () 以及 OneDrive for Business 网站 上文件夹的 DocumentLink SharePoint 路径。然后可以在搜索查询中使用此文件夹 ID 或路径来返回文件夹中的项目。
评论
若要返回位于 网站 或 SharePoint OneDrive for Business 文件夹中的内容,本主题中的脚本使用 DocumentLink 托管属性而不是 Path 属性。DocumentLink 属性比 Path 属性更可靠,因为它将返回文件夹中的所有内容,而 Path 属性不返回某些媒体文件。
运行目标集合之前 第 1 步:运行脚本以获取邮箱或站点的文件夹列表
第一步中运行的脚本返回邮箱文件夹或 SharePoint 和 OneDrive for Business 文件夹的列表,以及每个文件夹的相应文件夹 ID 或路径。运行此脚本时,它将提示您输入以下信息。
用户凭据:该脚本将使用您的凭据通过 Modern Exchange Online PowerShell 和安全与合规中心连接到 PowerShell。如前所述,您必须具有适当的权限才能成功运行此脚本。
要显示邮箱文件夹列表或站点文档链接(路径)名称列表:
将以下文本保存到文件名后缀为 .ps1 的 Windows PowerShell 脚本文件中;例如,GetFolderSearchParameters.ps1。
#########################################################################################################
# This PowerShell script will prompt you for: #
# * Admin credentials for a user who can run the Get-MailboxFolderStatistics cmdlet in Exchange #
# Online and who is an eDiscovery Manager in the Microsoft 365 compliance center. #
# The script will then: #
# * If an email address is supplied: list the folders for the target mailbox. #
# * If a SharePoint or OneDrive for Business site is supplied: list the documentlinks (folder paths) #
# * for the site. #
# * In both cases, the script supplies the correct search properties (folderid: or documentlink:) #
# appended to the folder ID or documentlink to use in a Content Search. #
# Notes: #
# * For SharePoint and OneDrive for Business, the paths are searched recursively; this means the #
# the current folder and all sub-folders are searched. #
# * For Exchange, only the specified folder will be searched; this means sub-folders in the folder #
# will not be searched. To search sub-folders, you need to use the specify the folder ID for #
# each sub-folder that you want to search. #
# * For Exchange, only folders in the user's primary mailbox will be returned by the script. #
#########################################################################################################
# Collect the target email address or SharePoint Url
$addressOrSite = Read-Host "Enter an email address or a URL for a SharePoint or OneDrive for Business site"
# Authenticate with Exchange Online and the Microsoft 365 compliance center (Exchange Online Protection - EOP)
if ($addressOrSite.IndexOf("@") -ige 0)
{
# List the folder Ids for the target mailbox
$emailAddress = $addressOrSite
# Connect to Exchange Online PowerShell
if (!$ExoSession)
{
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -ShowBanner:$false -CommandName Get-MailboxFolderStatistics
}
$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
}
elseif ($addressOrSite.IndexOf("http") -ige 0)
{
$searchName = "SPFoldersSearch"
$searchActionName = "SPFoldersSearch_Preview"
# List the folders for the SharePoint or OneDrive for Business Site
$siteUrl = $addressOrSite
# Connect to Security & Compliance Center PowerShell
if (!$SccSession)
{
Import-Module ExchangeOnlineManagement
Connect-IPPSSession
}
# Clean-up, if the script was aborted, the search we created might not have been deleted. Try to do so now.
Remove-ComplianceSearch $searchName -Confirm:$false -ErrorAction 'SilentlyContinue'
# Create a Content Search against the SharePoint Site or OneDrive for Business site and only search for folders; wait for the search to complete
$complianceSearch = New-ComplianceSearch -Name $searchName -ContentMatchQuery "contenttype:folder" -SharePointLocation $siteUrl
Start-ComplianceSearch $searchName
do{
Write-host "Waiting for search to complete..."
Start-Sleep -s 5
$complianceSearch = Get-ComplianceSearch $searchName
}while ($complianceSearch.Status -ne 'Completed')
if ($complianceSearch.Items -gt 0)
{
# Create a Compliance Search Action and wait for it to complete. The folders will be listed in the .Results parameter
$complianceSearchAction = New-ComplianceSearchAction -SearchName $searchName -Preview
do
{
Write-host "Waiting for search action to complete..."
Start-Sleep -s 5
$complianceSearchAction = Get-ComplianceSearchAction $searchActionName
}while ($complianceSearchAction.Status -ne 'Completed')
# Get the results and print out the folders
$results = $complianceSearchAction.Results
$matches = Select-String "Data Link:.+[,}]" -Input $results -AllMatches
foreach ($match in $matches.Matches)
{
$rawUrl = $match.Value
$rawUrl = $rawUrl -replace "Data Link: " -replace "," -replace "}"
Write-Host "DocumentLink:""$rawUrl"""
}
}
else
{
Write-Host "No folders were found for $siteUrl"
}
Remove-ComplianceSearch $searchName -Confirm:$false -ErrorAction 'SilentlyContinue'
}
else
{
Write-Error "Couldn't recognize $addressOrSite as an email address or a site URL"
}
在本地计算机上,打开 Windows PowerShell 并转到保存脚本的文件夹。
运行脚本;例如:
.\GetFolderSearchParameters.ps1
输入脚本提示您输入的信息。
该脚本显示指定用户的邮箱文件夹或站点文件夹列表。保持此窗口打开,以便您可以复制文件夹 ID 或文档链接名称并将其粘贴到步骤 2 中的搜索查询中。
暗示
您可以将脚本的输出重定向到文本文件,而不是在计算机屏幕上显示文件夹列表。此文件将保存到与脚本相同的文件夹中。例如,要将脚本输出重定向到文本文件,请在步骤 3 中运行以下命令: .\GetFolderSearchParameters.ps1 > StacigFolderIds.txt 然后,您可以从文件中复制文件夹 ID 或文档链接以用于搜索查询。
邮箱文件夹的脚本输出
如果您收到邮箱文件夹的 ID,脚本将连接到 Exchange Online PowerShell,运行 Get-MailboxFolderStatisics cmdlet,并显示指定邮箱中的文件夹列表。对于邮箱中的每个文件夹,脚本会在 FolderPath 列中显示文件夹的名称,在 FolderQuery 列中显示文件夹 ID。此外,该脚本将 folderId(即邮箱属性的名称)作为文件夹 ID。由于 folderid 属性是 folderid: searchable 属性,您将在步骤 2 的搜索查询中使用该搜索查询来搜索文件夹。
重要的
本文中的脚本收录将 Get-MailboxFolderStatistics 返回的 64 个字符的文件夹 ID 值转换为 48 个字符的索引格式以供搜索的编码逻辑。如果您只是在 PowerShell 中运行 Get-MailboxFolderStatistics cmdlet 来获取文件夹 ID(而不是运行本文中的脚本),使用该文件夹 ID 值的搜索查询将失败。您必须运行脚本以获取可用于内容搜索的格式正确的文件夹 ID。
下面是邮箱文件夹的脚本返回的输出示例。
步骤 2 中的示例显示了用于搜索用户“可恢复项目”文件夹中的“清除”子文件夹的查询。
网站 文件夹的脚本输出
如果要从 SharePoint 或 OneDrive for Business 网站 获取 documentlink 属性的路径,脚本将连接到安全与合规 PowerShell,创建新的内容搜索,在 网站 中搜索文件夹,然后显示位于指定 网站 中的文件夹列表。该脚本显示每个文件夹的名称并将文档链接前缀添加到文件夹 URL。由于 documentlink 属性是一个文档链接:
searchable 属性,因此您将在步骤 2 的搜索查询中使用 property:value 对来搜索该文件夹。该脚本最多显示 100 个 网站 文件夹。如果 网站 文件夹超过 100 个,则显示最新的文件夹。
下面是脚本返回的 网站 文件夹的示例输出。
步骤 2:使用文件夹 ID 或文档链接执行目标集合
运行脚本采集特定用户的文件夹 ID 列表或文档链接后,下一步是转到 Microsoft 365 合规中心并创建新的内容搜索来搜索特定文件夹。文件夹ID:文档链接:
您将在内容搜索关键字框中配置的搜索查询中使用 or property:value 对(如果使用 New-ComplianceSearch cmdlet),您将使用 or property:value 对作为 ContentMatchQuery 参数的值。您可以将 or folderid 文档链接属性与其他搜索参数或搜索条件结合使用。如果查询仅收录 folderid 或 documentlink 属性,则搜索将返回指定文件夹中的所有项目。
转到并使用您在步骤 1 中用于运行脚本的帐户和凭据登录。
在合规中心的左窗格中,单击“全部显示”>“内容搜索”,然后单击“新建搜索”。
在“关键字”框中,folderid:``documentlink:
/* 粘贴步骤 1 中脚本返回的 OR 值。
例如,以下屏幕截图中的查询将搜索用户“Recoverable Items”文件夹的“Purge”folderid 子文件夹中的任何项目(“Purge”子文件夹的属性值显示在步骤 1) 中的屏幕截图中:
重要的
文档链接搜索需要一个尾随星号“/*”。
在位置下,选择特定位置,然后单击修改。
根据您是搜索邮箱文件夹还是 网站 文件夹,请执行以下操作之一:
保存要搜索的内容位置后,单击“保存并运行”,输入内容搜索的名称,然后单击“保存”开始目标集合搜索。
目标集合的示例搜索查询
下面是一些在搜索查询中使用 folderid 和 documentlink 属性来执行目标集合的示例。占位符和文件夹ID:到文档链接:
节省空间。
更多信息
使用本文中的脚本执行目标集合时,请记住以下几点。