0

我有以下内容:

{
$matches[0]

$url = $matches[0]

$wc = new-object system.net.WebClient

$result = Invoke-WebRequest $url

$newresult = $result.Content -replace "`n",""

}

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

$targetfolder = $inbox.Folders | where-object { $_.name -eq "Backup" }

$targetfolder.items | where-object { $_.body -match "\bhttps://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-    9+&@#/%=~_|$]" } | % {$matches[0]}

它在文件夹中搜索电子邮件的正文以查找 url 示例电子邮件正文:

fred is good https://1.1.1.1:1111/fred. 

当前脚本为每个匹配的主体返回一个匹配列表。

我想要做的是将 % {$matches[0]} 部分传递给函数fred,但它似乎只传递最后一个匹配项,而不是全部,如果我将其更改为:

$targetfolder.items | where-object { $_.body -match "\bhttps://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-    9+&@#/%=~_|$]" } | fred $matches[0]

谢谢?

4

1 回答 1

0

您需要遍历每个项目,虽然我目前无法从这里测试它,但这样的事情应该可以工作:

$items = $targetfolder.items 

foreach($item in $items){
    where-object { 
    $item.body -match "\bhttps://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]" } |
    fred $matches[0]
}
于 2013-05-31T16:06:45.310 回答