如何使用Powershell指定收件箱的子文件夹 [英] How to specify a subfolder of Inbox using Powershell

查看:99
本文介绍了如何使用Powershell指定收件箱的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Powershell访问Outlook(2010)中名为子文件夹"的收件箱"子文件夹.

I'm trying to access a subfolder of "Inbox" named "subfolder" in outlook (2010) using Powershell.

$olFolderInbox = 6
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox)

# how do I specify a subfolder that's inside Inbox???
# I mean, "Inbox\subfolder" where "subfolder" is the name of the subfolder...

如何指定此子文件夹?

我确信这真的很简单,这就是为什么我要丢掉它".预先感谢!

I'm sure this is really simple, which is why I am about to "lose it." Thanks in advance!

*稍后在我的代码中, 我在正文中搜索搜索词",如果有匹配项,则将结果发送到文本文件.以下代码适用于我的收件箱:

*Later in my code, I search the body for a "searchterm" and send the results to a text file if there's a match. The following code works for my Inbox:

$inbox.items | foreach {
if($_.body -match "searchterm") {$_.body | out-file -encoding ASCII foo.txt} # prints to file...

我要查看收件箱的子文件夹,如上所述,而不是收件箱...

Instead of the inbox, I want to look at the subfolder of inbox as described above...

++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$olFolderInbox = 6
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox)
$targetfolder = $inbox.Folders | where-object { $_.name -eq "Subfolder" }
$targetfolder.items | foreach {
if($_.body -match "keyword") {$_.body | out-file -Append -encoding ASCII foo.txt} # keyword match prints body to file...
}

好的,我想现在可以了...

OK, I think this works now...

我不知道自己在做什么错,尽管这实际上是我使用Powershell的第一天,所以这并不奇怪.

I don't know what I was doing wrong, although it's literally my first day using Powershell, so it's no surprise, really.

推荐答案

$targetfolder = $inbox.Folders | where-object { $_.name -eq "subfolder" }
$targetfolder.items | where-object { $_.body -match "keyword" } | % { $_.body } # can then redirect the body to file etc.

不确定为什么您的最新编辑不起作用.您的结构看起来与我上面的结构类似,我已经根据自己的邮箱进行了验证.

not sure why your newest edit wouldn't work. Yours looks to be similar in construction to the one I have above, which I verified against my own mailbox.

编辑请确保如果您使用的是文件外文件,请附加结果,而不是每次匹配都覆盖该结果.

EDIT Be sure that if you're using out-file, you append the results rather than overwriting with each match.

这篇关于如何使用Powershell指定收件箱的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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