使用附件名称列出共享邮箱中的所有电子邮件 [英] Listing all emails on a shared mailbox with attachments name

查看:65
本文介绍了使用附件名称列出共享邮箱中的所有电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a very simple powershell script to collect some basic information about all the emails on a shared mailbox folder.

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)

This is working as expected, printing a table which can be exported as CSV, but the Attachments property just print System.__ComObject. So, I need to replace the "Attachments" column with a list of the attachments names ($_.Attachments::DisplayName)

我尝试迭代结果以解决此问题,例如:

I tried to iterate the results to fix this, with something like:

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

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

But this prints only the attachment information and not the rest of the data. Also, adding all the fields between {} cause powershell to print one field per line, so it can't be exported as CSV.

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

Can you help me to replace the Attachments column properly?

推荐答案

更改最后一行:

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

然后您可以将其通过管道传输到 |ft -wrap 以扩展"附件列.

you can then pipe it to | ft -wrap to "expand" the Attachments column.

这篇关于使用附件名称列出共享邮箱中的所有电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆