我有以下内容:
{
$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]}
它搜索文件夹中的电子邮件正文,以查找网址示例:
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]
感谢?
答案 0 :(得分:0)
你需要遍历每个项目,这样的东西应该可以工作,虽然我现在无法从这里测试它:
$items = $targetfolder.items
foreach($item in $items){
where-object {
$item.body -match "\bhttps://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]" } |
fred $matches[0]
}