Solved

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

Posted on 2016-08-17
3
61 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 6

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:
DeBlackman 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this video we show how to create a Contact 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 >> Contact ta…
In this video we show how to create an email address policy 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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now