Solved

How do I know if an Exchange mailbox has an archive?

Posted on 2016-08-17
3
122 Views
Last Modified: 2016-08-18
I am writing a PowerShell Script for Exchange 2013 to export all mailboxes and archives to a PST.  When there is an archive the script works with no issues, however when there is none I get the message below:

Mailbox 'Alex Simmons' has no archive. + CategoryInfo          : InvalidArgument: (True:SwitchParameter) [New-MailboxExportRequest], MailboxLacksArchivePermanentException + FullyQualifiedErrorId : DCF7E01A,Microsoft.Exchange.Management.RecipientTasks.NewMailboxExportRequest + PSComputerName        : 2013-exchange.contoso.com

Does anyone have any input on how I can determine if there is an archive.  Below I have the PowerShell script that I am trying to run.  I would think there is some type of ‘if’ command that would say, if(mailbox == IsArhcive) extract it.

#Iterate through each mailbox on the current Exchange server.
foreach ($mailBoxName in (Get-Mailbox)){
	#Start export of current mailbox.
	New-MailboxExportRequest -Mailbox $mailBoxName.Alias -FilePath "${uncOutputDirectoryString}$($mailBoxName.Alias).pst"

	#Wait for the export to complete.
	while(!(Get-MailboxExportRequest -Mailbox $mailBoxName.Alias -Status Completed))
	{
		Start-Sleep -s 300
	}
			
	
	#Export Archive
	#ToDo: How do i determine if there is an archive?
	New-MailboxExportRequest -Mailbox $mailBoxName.Alias -IsArchive -FilePath "${uncOutputDirectoryString}$($mailBoxName.Alias).IsArchive.pst"

	#Wait for the export to complete.
	while(!(Get-MailboxExportRequest -Mailbox $mailBoxName.Alias -Status Completed))
	{
		Start-Sleep -s 300
	}
}

Open in new window


Any help would be greatly appreciated.
0
Comment
Question by:rye004
3 Comments
 
LVL 7

Expert Comment

by:David Sankovsky
ID: 41760575
I haven't a ready code, but if you use Get-Mailbox <mailbox> |fl ArchiveDataBase you should get an empty string if it has none.

That should help you filter out which mailboxes do have archives.
0
 
LVL 9

Accepted Solution

by:
Ibrahim Benna earned 500 total points
ID: 41760886
To add on to David's suggestion, you can run the following command to get you a list of mailboxes that only have archives

get-mailbox | where {$_.ArchiveDatabase -ne $null}

To do the opposite and find mailboxes without any archive mailboxes run this


get-mailbox | where {$_.ArchiveDatabase -eq $null}
0
 

Author Comment

by:rye004
ID: 41761360
DeBlackman,  Thank you for your input, it was very helpful.  I have written the following below which I think is going to work.
function ExportMailBox ($mailBoxName, $isArchive, $outputPath){

    #Call New-MailboxExportRequest here.

}

"mailboxes with an archive:"
foreach ($mailBoxName in (Get-Mailbox | where {$_.ArchiveDatabase -ne $null})){

    ExportMailBox -mailBoxName $mailBoxName, -isArchive False, -outputPath "...."
    ExportMailBox -mailBoxName $mailBoxName, -isArchive True, -outputPath "...."

}

"mailboxes without an archive:"
foreach ($mailBoxName in (Get-Mailbox | where {$_.ArchiveDatabase -eq $null})){

    ExportMailBox -mailBoxName $mailBoxName, -isArchive False, -outputPath "...."

}

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question