Importieren von .PST-Dateien in Outlook und dann in amber

1. Importieren Sie die PST-Datei in die Windows-App „Outlook (Classic)“

2. Stellen Sie sicher, dass die .pst-Datei in Ihrer Postfachübersicht angezeigt wird

3. Führen Sie das folgende Skript aus

Dieses Skript exportiert nur den Ordner „Posteingang“ und alle seine Unterordner/Elemente. Wenn Sie andere Hauptordner haben, ändern Sie bitte Zeile 30

$posteingang = $rootFolder.Folders.Item("Posteingang".

Ändern Sie außerdem Zeile 2 entsprechend Ihren persönlichen Angaben.

$savePath = "C:\Users\XXXXX\Downloads\test"

# --- Configuration ---
$savePath = "C:\Users\XXX\Downloads\test"

# Create target folder if it doesn't exist
if (-not (Test-Path $savePath)) {
    New-Item -ItemType Directory -Path $savePath -Force | Out-Null
}

# --- Connect to Outlook ---
$outlook = New-Object -ComObject Outlook.Application
$namespace = $outlook.GetNamespace("MAPI")

# --- Find the PST store "Outlook-Datendatei" ---
$store = $null
foreach ($s in $namespace.Stores) {
    if ($s.DisplayName -eq "Outlook-Datendatei") {
        $store = $s
        break
    }
}

if (-not $store) {
    Write-Error "PST store 'Outlook-Datendatei' not found."
    exit 1
}

# --- Navigate to Posteingang ---
try {
    $rootFolder = $store.GetRootFolder()
    $posteingang = $rootFolder.Folders.Item("Posteingang")
} catch {
    Write-Error "Folder 'Posteingang' not found in the PST."
    exit 1
}

# --- Recursive export function ---
function Export-MailFolder {
    param(
        [Parameter(Mandatory)] $OutlookFolder,
        [Parameter(Mandatory)] [string] $TargetPath
    )

    $olMSG = 3

    # Create the matching subfolder on disk
    if (-not (Test-Path $TargetPath)) {
        New-Item -ItemType Directory -Path $TargetPath -Force | Out-Null
    }

    # Export all mail items in this folder
    foreach ($item in $OutlookFolder.Items) {
        if ($item.Class -eq 43) {
            $fileName = $item.Subject -replace '[\\/:*?"<>|]', '_'

            if ([string]::IsNullOrWhiteSpace($fileName)) {
                $fileName = "NoSubject"
            }

            if ($fileName.Length -gt 150) {
                $fileName = $fileName.Substring(0, 150)
            }

            $fullPath = Join-Path $TargetPath "$fileName.msg"

            if (Test-Path $fullPath) {
                $timestamp = $item.ReceivedTime.ToString("yyyyMMdd_HHmmss")
                $fullPath = Join-Path $TargetPath "${fileName}_${timestamp}.msg"
            }

            $item.SaveAs($fullPath, $olMSG)
            $script:counter++
            Write-Host "Saved:$fullPath"
        }
    }

    # Recurse into subfolders
    foreach ($subfolder in $OutlookFolder.Folders) {
        $subPath = Join-Path $TargetPath $subfolder.Name
        Export-MailFolder -OutlookFolder $subfolder -TargetPath $subPath
    }
}

# --- Run the export ---
$counter = 0
Export-MailFolder -OutlookFolder $posteingang -TargetPath $savePath
Write-Host "`nDone! $counter emails exported to $savePath"

4. Stellen Sie sicher, dass Sie die .msg-Dateien in einem Ordner ablegen, der mit Amber verbunden ist