2016-06-29 5 views
2

Derzeit versuche ich Anhangnamen aus E-Mails innerhalb einer PST-Datei zu erhalten. Ich möchte dies über Powershell tun. Meine Code-Klammer funktioniert soweit, bis auf eine Sache. Es schreibt nur System .__ ComObject als Anlagenamen. Irgendwelche Ideen?Powershell: Anhänge von E-Mails aus PST-Datei abrufen

## 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)) 

    } 
} 

(ich Schleife durch einen Ordner mit PST, der gut arbeitet)

Vielen Dank für Hilfe/Antworten

Antwort

1

Try this:

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

funktioniert gut! Vielen Dank! – MaxM

Verwandte Themen