powershell - 列出共享邮箱上的所有电子邮件及其附件名称

标签 powershell outlook

我创建了一个非常简单的 powershell 脚本来收集有关共享邮箱文件夹上所有电子邮件的一些基本信息。

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")
$Inbox = $namespace.pickfolder()
$Inbox.items | Select-Object -Property Categories, Attachments, Subject, ReceivedTime

这按预期工作,打印一个可以导出为 CSV 的表格,但 Attachments 属性仅打印 System.__ComObject。因此,我需要将“附件”列替换为附件名称列表 ($_.Attachments::DisplayName)

我尝试迭代结果来解决这个问题,例如:

$Inbox.items | Select-Object -Property Categories, Attachments, 
Subject, ReceivedTime | ForEach-Object -Process {$_.Attachments::DisplayName}

但这仅打印附件信息,而不打印其余数据。此外,在 {} 之间添加所有字段会导致 powershell 每行打印一个字段,因此无法将其导出为 CSV。

你能帮我正确替换附件栏吗?

最佳答案

更改最后一行:

$Inbox.items |Select-Object -Property Categories,Subject,   
ReceivedTime,@{name="Attachments";expression={$_.Attachments|%{$_.DisplayName}}}

然后您可以将其通过管道传输到 | ft -wrap 以“展开”附件列。

关于powershell - 列出共享邮箱上的所有电子邮件及其附件名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21940851/

相关文章:

windows - 运行批处理文件,运行 PowerShell 文件,运行批处理文件...以管理员身份

powershell - 从命令行将 pfx 文件导入到特定的证书存储中

python - 使用 python 和 Redemption RDO 从 Outlook 获取签名

java - 无法使用 mailR 包通过 Outlook.com 发送电子邮件

c# - 用于打开 .MSG 文件的 OpenSharedItem 在 Outlook C# 中显示错误

powershell - 使用 ARM PowerShell 将网络安全组分配给网络接口(interface)

powershell - TFS 2017-从TFS服务器而非代理运行Powershell脚本

powershell - 在调试项目上运行PowerShell脚本

vba - Item.To从ItemLoad VBA事件上的Outlook olMail-Item中提取

vba - 使用 VBA 将电子邮件消息写入 Outlook 中的平面文件