PowerShell搜索邮箱搜索查询问题 [英] PowerShell Search-Mailbox Search Query Troubles

查看:58
本文介绍了PowerShell搜索邮箱搜索查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试一些PowerShell脚本.我想在一段时间后从收件箱中删除语音邮件.该代码获取组织内的所有邮箱,并将它们通过管道传递到搜索邮箱".然后,我需要使用-searchquery选项查询邮箱.似乎不喜欢如何将Date变量放入查询中.

Attempting my hand at some PowerShell scripting. I would like to remove Voice Messages from Inbox's after a certain period of time. The code gets all mailboxes within an organization and pipes them to a Search-Mailbox. Then I need to query the mailboxes using the -searchquery option. It does not seem to like how I am placing the Date variable into the query.

$Date = (Get-Date).AddDays(-19)
$Test = $Date.toString("MM/dd/yyyy")
$SB = [scriptblock]::create("Sent: $Test AND Attachment:`"VoiceMessage.wav`"")
Get-Mailbox | Search-Mailbox -TargetMailbox "Example" -TargetFolder "Searching" -SearchQuery $SB -LogOnly -LogLevel Full

执行脚本时,PowerShell声明以下内容:

Edit 1: PowerShell is stating the following when the script is executed:

Search-Mailbox:输入对象不能绑定到任何参数 对于该命令,或者是因为该命令不占用管道 输入或输入及其属性与以下任何一个都不匹配 需要管道输入的参数.在第3行:Char:25

Search-Mailbox : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:3 Char:25

编辑二:将问题中的代码调整为有效的代码.谢谢大家的帮助!

Edit Two: Adjusted the Code in my question to the code that works. Thanks for all the help everyone!

推荐答案

根据由Exchange搜索索引的邮件属性).

使用与property:value格式匹配的语法.值不区分大小写,并且运算符后不能有空格.如果有空格,则将仅对全文搜索您的预期值.例如,要:pilarp搜索"pilarp"作为关键字,而不是搜索发送给pilarp的邮件.

Use syntax that matches the property:value format. Values are not case-sensitive, and they can’t have a space after the operator. If there is a space, your intended value will just be full-text searched. For example to: pilarp searches for "pilarp" as a keyword, rather than for messages that were sent to pilarp.

减少并非绝对必需的引号将有助于避免将其转义.它还支持其他运算符比较日期等内容. 尝试使用-SearchQuery:

Reducing the quotes that aren't absolutely required will help avoid needing to escape them. It also supports other operators for comparing things like dates. Try this for the -SearchQuery:

"Attachment:VoiceMessage.wav AND Received<=$Date2"

我自己的租户Search-Mailbox要注意的一件事根本不会搜索附件,尽管附件是New-MailboxSearch的受支持"关键字.我不得不求助于身体中的单词以获得理想的结果.我确实等待了几个小时,以查看索引编制是否很慢,但没有任何变化.也许您会有更好的运气.

One thing to note on my own tenant Search-Mailbox wouldn't search the attachments at all, despite Attachment being a "supported" key word for New-MailboxSearch. I had to resort to finding words in the body to get desired reults. I did wait a few hours to see if it might be slow indexing, but nothing changed. Perhaps you will have better luck.

另请注意此页面提到:

如果要从中删除邮件的邮箱只有一个项目 恢复已启用,您必须先禁用该功能.

If the mailbox from which you want to delete messages has single item recovery enabled, you must first disable the feature.

这不是绝对要求.在不关闭此功能的情况下,用户可能能够恢复语音邮件.可能对您的情况没什么大碍.

That is NOT an absolute requirement. Without turning that off, users may be able to recover the voicemail. Probably not a big deal for your situation.

这篇关于PowerShell搜索邮箱搜索查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆