Exporting .PST to named folders in two locations based in property values

If I understand correctly you want to export those without litigation hold to the first path and for those with LitigationHoldEnabled flagged to the LegalHold path. You can combine all steps into the following.

$Users = Get-Content "C:\Disabledusers.csv"
$date = Get-Date
$date = $date.ToString("MM-dd-yyyy")
ForEach ($user in $users)
{

    if((Get-Mailbox $user).litigationholdenabled -eq $true)
    {
        $newPath = Join-Path "\\network-location\t$\Users$\Legalhold" -childpath "$user $date"
        $null = New-Item $newPath -ItemType directory
        $exportpath = Join-Path $newPath "$user.pst"
        New-MailboxExportRequest -Mailbox $user -FilePath $exportpath
    }
    else
    {

        $newPath = Join-Path "\\network-location\t$\Users$" -childpath "$user $date"
        $null = New-Item $newPath -ItemType directory
        $exportpath = Join-Path $newPath "$user.pst"
        New-MailboxExportRequest -Mailbox $user -FilePath $exportpath
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top