我有以下内容:
{
$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]
谢谢?