PowerShell script exchange
Post Reply
KamT
Novice
Posts: 5
Liked: never
Joined: Sep 08, 2023 9:28 am
Contact:

Restoring Exchange Items by date range

Post by KamT »

Hi all,

Background
got a 2TB Journaling mailbox in Exchange Veeam backup containing email of last 10 years.

Requirment
the mailbox is growing too big and want to break it down by year into multiple smaller mailboxes

Problem
tried the Advance search (by year) in the Veeam Explorer GUI but the DB is too big and the Search is never completed.

Question?
is there a parameter on Veeam Powershell to restore exchange items by specifying the Date range?

Many thanks,

KamT
Mildur
Product Manager
Posts: 9848
Liked: 2607 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Restoring Exchange Items by date range

Post by Mildur »

Hello KamT

In PowerShell, you can use the query parameter to get the items per year:
Get-VEXItem

The query parameter allows you to use the same filters outlook allows you to use.
https://support.office.com/en-us/articl ... 6FB895A8DA

Sample code for year 2022 (swiss date format, may be different with your servers location settings.
Disclaimer: I didn't run the commands in my lab. But they should work. If not, please let me know.

Code: Select all

$organization = Get-VBOOrganization -Name "Org Name"
$session = Start-VBOExchangeItemRestoreSession -LatestState -Organization $organization
$database = Get-VEXDatabase -Session $session -Name tennant.onmicrosoft.com
$mailbox = Get-VEXMailbox -Database $database -Name "journalingmailbox"
$items = Get-VEXItem -Database $database -mailbox $mailbox -Query "received:1/1/2022..31/12/2022" 
Export-VEXItem -Item $items -To "C:\Export"

Best,
Fabian
Product Management Analyst @ Veeam Software
KamT
Novice
Posts: 5
Liked: never
Joined: Sep 08, 2023 9:28 am
Contact:

Re: Restoring Exchange Items by date range

Post by KamT »

Thanks Fabian,

and sorry I should be more specified on the current environment.

the current environment is a Exchange 2019 on-premises ( not Exchange Online)

and trying to restore to the same environment but difference mailboxes by year.

Thanks again,

KamT
Mildur
Product Manager
Posts: 9848
Liked: 2607 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Restoring Exchange Items by date range

Post by Mildur »

Hi KamT

We can use a similar method for your scenario (Example 3 with filter).

Code: Select all

$restorepoint = Get-VBRApplicationRestorePoint -Name "VM_NAME" -Exchange | Sort-Property CreationTime -Descending | Select -First 1
$session = Start-VBRExchangeItemRestoreSession -RestorePoint $restorepoint

$database = Get-VEXDatabase -Session $session -Name "DB_Filename.edb"
$mailbox = Get-VEXMailbox -Database $database -Name "journalingmailbox"

$folder = Get-VEXFolder -Mailbox $mailbox -Name "Inbox"
$items = Get-VEXItem -Database $database -mailbox $mailbox -Folder $folder-Query "received:1/1/2015..31/12/2015" 

$creds = Get-Credential
Restore-VEXItem -Item $items -Server ExchangeCAS.Domain.local -Credential $creds -RestoreChangedItem -RestoreDeletedItem -TargetMailbox "2015@abc.onmicrosoft.com"
Best,
Fabian
Product Management Analyst @ Veeam Software
KamT
Novice
Posts: 5
Liked: never
Joined: Sep 08, 2023 9:28 am
Contact:

Re: Restoring Exchange Items by date range

Post by KamT »

Code: Select all

$restorepoint = Get-VBRApplicationRestorePoint -Name "VM_NAME" -Exchange | Sort-Object CreationTime -Descending | Select -First 1
$session = Start-VBRExchangeItemRestoreSession -RestorePoint $restorepoint

$database = Get-VEXDatabase -Session $session -Name "DB_Filename.edb"
$mailbox = Get-VEXMailbox -Database $database -Name "journalingmailbox"

$folder = Get-VEXFolder -Mailbox $mailbox -Name "Inbox"
$items = Get-VEXItem -Folder $folder-Query "received:1/1/2015..31/12/2015" 

$creds = Get-Credential
Restore-VEXItem -Item $items -Server ExchangeCAS.Domain.local -Credential $creds -RestoreChangedItem -RestoreDeletedItem -TargetMailbox "2015@abc.onmicrosoft.com"
Thanks Fabian

amanded a bit and working like a charm.

just don't know how long it takes to finish the search for 10million of items.

Many thanks,

KamT
Mildur
Product Manager
Posts: 9848
Liked: 2607 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Restoring Exchange Items by date range

Post by Mildur »

You're welcome.

Thanks for providing the updated code with me.
It may take some time. Unfortunately I don't have any performance numbers to share.
Please let me know how the restore has worked. We would be happy for every feedback we can get.

Best,
Fabian
Product Management Analyst @ Veeam Software
KamT
Novice
Posts: 5
Liked: never
Joined: Sep 08, 2023 9:28 am
Contact:

Re: Restoring Exchange Items by date range

Post by KamT »

Hi Fabian,

the performance of restoration is super slow and also kind of weird.

it restores 100 items, stops 5 mins and then restores another 100 items, stops another 5 min and so on.....

do you know if this is something to do with the restore parameters? or any suggestion please?

Restore-VEXItem -Item $items -Server ex04 -Credential $Credential -TargetMailbox "Email.Journal2020@xxxx.com" -MarkAsUnread -RestoreChangedItem -RestoreDeletedItem

Many thanks,

KamT
KamT
Novice
Posts: 5
Liked: never
Joined: Sep 08, 2023 9:28 am
Contact:

Re: Restoring Exchange Items by date range

Post by KamT »

it should be related to the items in the inbox, the more items in the inbox, the more it is slower.
Mildur
Product Manager
Posts: 9848
Liked: 2607 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Restoring Exchange Items by date range

Post by Mildur »

Hi Kam

That's possible.
When I was working for a service provider, I was responsible for migrating Exchange data to the cloud.
My experience was, that migration tools always had less good performance when migrating folders with thousands of objects. How many objects does the mailbox have stored in a single mailbox folder?

Best,
Fabian
Product Management Analyst @ Veeam Software
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 3 guests