下面的脚本为我提供了电子邮件邮箱中的项目列表以及相关的元数据。该脚本有效,但不指示电子邮件是否有附件。 我该如何得到这个?
我尝试将
hasAttachment
添加到下面脚本中的属性行,这返回了完全空白的值。 我还尝试了 Attachments
,它为每个项目返回 System.__ComObject
。
Set-StrictMode -Version "Latest"
$ErrorActionPreference = "Stop"
function Get-MailFromOutlookFolder
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[Object] $ParentFolder
)
$items = @()
foreach ($folder in $ParentFolder.Folders)
{
foreach ($item in ($folder | Select-Object -ExpandProperty "Items"))
{
if ($item.Class -eq 43)
{
# process email
$items += $item | Select-Object -Property "ConversationTopic", "ReceivedTime", "Body", "SenderName", "HasAttachment","SenderEmailAddress", @{ "Label" = "Folder"; "Expression" = { $_.Parent.Name } }
}
}
# process (sub)folder items
$items += Get-MailFromOutlookFolder -ParentFolder $folder
}
return $items
}
$outlook = New-Object -Com "Outlook.Application"
$mapi = $outlook.GetNamespace("MAPI")
$mailboxRoot = $mapi.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox).Parent
$results = Get-MailFromOutlookFolder -ParentFolder $mailboxRoot
$results | Export-Csv -Path "C:\Blah\email.csv"
我用
$items += $item | Select-Object -Property "*" = { $_.Parent.Name }
替换了中间线,并获得了可能的属性列表(请参见下文),但唯一相关的是 Attachments
- 我已经知道这不起作用。
Application, Class, Session, Parent, Actions, Attachments, BillingInformation, Body, Categories, Companies, ConversationIndex, ConversationTopic, CreationTime, EntryID, FormDescription, GetInspector, Importance, LastModificationTime, MAPIOBJECT, MessageClass, Mileage, NoAging, OutlookInternalVersion, OutlookVersion, Saved, Sensitivity, Size, Subject, UnRead, UserProperties, AlternateRecipientAllowed, AutoForwarded, BCC, CC, DeferredDeliveryTime, DeleteAfterSubmit, ExpiryTime, FlagDueBy, FlagRequest, FlagStatus, HTMLBody, OriginatorDeliveryReportRequested, ReadReceiptRequested, ReceivedByEntryID, ReceivedByName, ReceivedOnBehalfOfEntryID, ReceivedOnBehalfOfName, ReceivedTime, RecipientReassignmentProhibited, Recipients, ReminderOverrideDefault, ReminderPlaySound, ReminderSet, ReminderSoundFile, ReminderTime, RemoteStatus, ReplyRecipientNames, ReplyRecipients, SaveSentMessageFolder, SenderName, Sent, SentOn, SentOnBehalfOfName, Submitted, To, VotingOptions, VotingResponse, Links, ItemProperties, BodyFormat, DownloadState, InternetCodepage, MarkForDownload, IsConflict, IsIPFax, FlagIcon, HasCoverSheet, AutoResolvedWinner, Conflicts, SenderEmailAddress, SenderEmailType, EnableSharedAttachments, Permission, PermissionService, PropertyAccessor, SendUsingAccount, TaskSubject, TaskDueDate, TaskStartDate, TaskCompletedDate, ToDoTaskOrdinal, IsMarkedAsTask, ConversationID, Sender, PermissionTemplateGuid, RTFBody, RetentionPolicyName, RetentionExpirationDate
我是否必须打开 com.object,如果是,我该怎么做?
您需要使用
PR_HASATTACH
检索
"http://schemas.microsoft.com/mapi/proptag/0x0E1B000B"
(DASL 名称
MailItem.PropertyAccessor.GetProperty
)MAPI 属性
请注意,循环遍历文件夹中的所有项目是一个非常糟糕的主意 - 使用
Items.Restrict
或 Items.Find/FindNext
限制匹配项目的数量,或者(如果您确实需要读取文件夹中的所有项目)使用检索属性使用 MAPITable.GetTable 从多个项目中获取 - 首先调用 Columns.Add
来指定 PR_HASATTACH
和其他属性。