我正在使用下面的代码从电子邮件中下载基于主题的附件,但我不能使用like操作员来检查主题并下载,下面是我使用的代码
我正在尝试像Test Powershell这样的科目,但我无法实现这一目标
**
$filepath = “D:\PowerShell”
$filter="[Subject]=Test Powershell"
$myNow = get-date -format "yyyy-MM-dd_hh-mm-ss"
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$namespace.Logon("profilename","mypassword",$false,$false)
$folder = $namespace.getDefaultFolder($olFolders::olFolderInBox)
#$folder.items|select *
$folder.items.Restrict($filter) |
select -Expand Attachments | % {
for ($i = $_.Count; $i; $i--) {
$_.Item($i).SaveAsFile("$filepath\$($_.Item($i).FileName)")
}
}**
发布于 2021-08-10 17:44:02
匹配字符串属性时,可以使用一对单引号(')或一对双引号(")来分隔属于筛选器的字符串。
在Jet或DASL查询中指定筛选器时,如果使用一对单引号分隔属于筛选器一部分的字符串,并且该字符串包含另一个单引号或撇号,则在单引号或撇号之前添加一个单引号作为转义字符。如果使用一对双引号来分隔字符串,请使用类似的方法。如果字符串包含双引号,则在双引号之前添加一个双引号作为转义字符。
例如,在筛选Subject属性等于单词Test Powershell的DASL筛选器字符串中,整个筛选器字符串由一对双引号分隔,嵌入的字符串Test Powershell由一对单引号分隔。此筛选器字符串中有三个字符需要转义:用于https://schemas.microsoft.com/mapi/proptag/0x0037001f属性引用的开始双引号和结束双引号,以及单词Test Powershell的value条件中的撇号。
$filter = "@SQL=""https://schemas.microsoft.com/mapi/proptag/0x0037001f"" = 'Test Powershell'"或
$filter = "@SQL=""https://schemas.microsoft.com/mapi/proptag/0x0037001f"" like '%Test Powershell%'"https://stackoverflow.com/questions/68726412
复制相似问题