【问题标题】:Powershell: Get Attachments of E-Mails from PST FilePowershell:从 PST 文件中获取电子邮件的附件
【发布时间】:2016-11-01 07:59:54
【问题描述】:

目前,我正在尝试从 PST 文件中的电子邮件中获取附件名称。我想通过 Powershell 做到这一点。到目前为止,我的代码括号工作正常,除了一件事。它只是将 System.__ComObject 写为附件名称。有什么想法吗?

## Path where the PSTFiles are
$PSTArr = Get-ChildItem -Path .\ -Recurse
$Attachments = @()

## Processing

ForEach ($PST in $PSTArr) {
    if ($PST.Name -like "*.pst") {
    [string]$pstPath = $PST.FullName
    Write-Output ("Checking File: " + $pstPath)

    # Lets see if there is a running outlook process
    $oProc = ( Get-Process | where { $_.Name -eq "OUTLOOK" } )
    if ( $oProc -eq $null ) { Start-Process outlook -WindowStyle Hidden; Start-Sleep -Seconds 5 }
    $outlook = New-Object -ComObject Outlook.Application

    # Assign namespace
    $namespace = $outlook.GetNamespace("MAPI")

    # Add PST
    $namespace.AddStore($pstPath)
    $pstStore = ( $nameSpace.Stores | where { $_.FilePath -eq $pstPath } )

    # Add RootFolder of the PST
    $pstRootFolder = $pstStore.GetRootFolder()

    # Get attachments of the E-Mails
    $Attachments += $pstRootFolder.Items | Select Attachment

    # Disconnect PST File
    $namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$namespace,($pstRootFolder))

    }
}

(我正在循环使用 PST 的文件夹,效果很好)

感谢您的帮助/回答

【问题讨论】:

    标签: email powershell outlook attachment pst


    【解决方案1】:

    试试这个:

    $Attachments = $pstRootFolder.Items | ForEach-Object {
        $_.Attachments | Select-Object -ExpandProperty FileName
    }
    

    【讨论】:

    • 工作正常!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-11-06
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    • 2011-09-19
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多