我编写了以下 Powershell 代码,该代码循环遍历给定“.eml”文件中的所有附件。 我的目标是能够将每个附件提取到本地目录。
到目前为止,我只能打印文件名(以查看循环确实访问附件)。
提前谢谢您。
$emlFn = "thedirectory\file.eml"
$adoDbStream = New-Object -ComObject ADODB.Stream
$adoDbStream.Open()
$adoDbStream.LoadFromFile($emlFn)
$cdoMessage = New-Object -ComObject CDO.Message
$cdoMessage.DataSource.OpenObject($adoDbStream, "_Stream")
foreach($attachment in $cdoMessage.Attachments){
Write-Output $attachment.FileName
#I need some code here to save each attachment locally
}
$adoDbStream.Close()
根据 Exchange Server 2003 SDK 文档,用于附件的接口公开了
SaveToFile
方法 - 将完整路径传递给它以将附件保存到磁盘:
# construct output path from current directory + attachment filename
$exportPath = Join-Path $PWD $attachment.FileName
# save to disk
$attachment.SaveToFile("$exportPath")