Powershell:从PST文件中获取电子邮件的附件

时间:2016-06-29 14:24:15

标签: email powershell outlook attachment pst

目前,我正在尝试从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' s循环浏览文件夹,工作正常)

感谢您的帮助/答案

1 个答案:

答案 0 :(得分:1)

试试这个:

GROUP BY TRUNC( Departure + 2/24 ),
         FLOOR( ( Departure + 2/24 - TRUNC( Departure + 2/24 ) ) * 3 )