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



当前,我正在尝试从PST文件中的电子邮件中获取附件名称。我想通过PowerShell做到这一点。到目前为止,我的代码支架运行良好,除了一件事。它只是写入系统。__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的文件夹循环,可以很好地工作)

感谢您的帮助/答案

尝试以下:

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

相关内容

  • 没有找到相关文章

最新更新