Retrieve all mailboxes where forwarding address is enabled

I was recently looking at retrieving all mailboxes where the forwarding address was enabled as part of the delivery options and to return the mailbox name, forwarding address and if the option to deliver message to both the forwarding address and mailbox is enabled and export this information to an output file.

I was able to do this by running the below in the Microsoft Exchange Management Shell:, by retrieving all mailboxes where the object ‘ForwardingAddress’ is not equal to null and by selecting the Name, ForwardingAddress and DeliverToMailboxAndForward objects and exporting to a CSV file.

Get-Mailbox | Where-Object {$_.ForwardingAddress -ne $null} | Select Name, ForwardingAddress, DeliverToMailboxAndForward | Export-CSV D:\Output\ForwardingAddresses.csv -NoTypeInformation
Advertisements

Using a Content Filter in Mailbox Export Requests

I recently wrote about performing a bulk export of mailboxes to PST from a collection (https://deangrant.wordpress.com/2013/10/08/bulk-export-of-exchange-mailboxes-from-a-collection/), in this script the entire contents of the mailbox was exported.

However, in instances where you only require to export a particular date range, you can use the Content Filter switch as part of the New-MailboxExportRequest cmdlet in Microsoft Exchange.

For Example, if I was looking to export mail items for the previous calendar month, I could run the following:

New-MailboxExportRequest -Mailbox <Mailbox Name> -ContentFilter {(Received -le '30/09/2013') -and (Received -ge '01/09/2013')} -FilePath \\Server\Share\Mailbox.pst

This would export all mail items which are greater than or equal to 01/09/2013 and less than or equal to 30/09/2013.

This can be particular useful, if performing a large mailbox export where the approach could be to perform an initial export of all the data and then run incremental style exports by using the content filter.

Bulk Disable Mailboxes in Exchange 2010

In a recent post, I wrote about performing a bulk export of mailboxes from a collection (https://deangrant.wordpress.com/2013/10/08/bulk-export-of-exchange-mailboxes-from-a-collection/), now that I have performed the bulk export I am looking to disable to the mailboxes using the same collection list.

I will load the collection of mailboxes from a CSV file using the get-content cmdlet to get the content of the file (\\Server\Share\Mailboxes.csv) which contains the alias name of the mailbox.

$Mailboxes = Get-Content "\\Server\Share\Mailboxes.csv"

Now that we have loaded a collection of mailboxes, we will run a script block to disable each mailbox.

ForEach ($Mailbox in $Mailboxes)
{ 
Disable-Mailbox -Identity $Mailbox -Confirm:$false
}

Bulk Export of Exchange Mailboxes from a Collection

I am currently looking at performing a bulk export of mailboxes from Exchange 2010 using the New-MailboxExportRequest cmdlet from a collection within a CSV file.

Firstly, I will want to remove any existing Mailbox Export Requests as I want to provide the status of the bulk export as the final step of the process with no previous history.

Get-MailboxExportRequest | Remove-MailboxExportRequest

Now, I want to generate the collection of mailboxes from reading the content of a file, which contains only the alias of each mailbox. In the below example, I am using the filename \\Server\Share\MailboxAlias.csv.

$Aliases = Get-Content "\\Server\Share\MailboxAlias.csv"

Now I want to request a mailbox export for each mailbox in the collection and export the PST with the Mailbox Name as the filename.  Therefore, the script block will firstly return all the mailbox attributes based on the mailbox alias name in the collection.

Also, by default Microsoft Exchange will auto generate 10 unique names for each mailbox export request. In this instance this is an insufficient amount to complete the bulk export. Therefore, we will specify the mailbox alias as the mailbox export request name.

ForEach ($Alias in $Aliases) 
{ 
$Mailbox = Get-Mailbox -Identity $Alias
New-MailboxExportRequest -Name $Mailbox.Alias -Mailbox $Mailbox.Alias -FilePath "\\Server\Share\" + $Mailbox.Name + ".pst"
}

At the final stage of the process I want to export the mailbox request status, therefore I will need to suspend the collection of this until all the export requests are reported as Completed.

I will perform this step by returning the mailbox export requests until all items are Completed and then export the mailbox request status to a CSV.

Do { 
$Queue = Get-MailboxExportRequest | Where-Object {$_.Status -ne "Completed"} 
} 
Until ($Queue -eq $null)

Get-MailboxExportRequest | Export-Csv "\\Server\Share\GetMailboxExportRequest.csv" -NoTypeInformation

The term “New-MailboxExportRequest” is not recognized

I was recently attempting to run a mailbox export request to a PST file in Exchange 2010 Service Pack 3, on running the New-MailboxExportRequest cmdlet, I was presented with the following error message:

The term "New-MailboxExportRequest" is not recognized.

In order to resolve this issue I had to grant the account performing the export request the ‘Import Export Mailbox’ role assignment as below.

New-ManagementRoleAssignment –Role “Mailbox Import Export” –User "DOMAIN\USER"

Once I restarted my powershell session, I was able to succesfully run the New-MailboxExportRequest cmdlet.

Get Mailbox Database Size and Convert Default Item Size Values

I am looking at extracting mailbox database sizes for a number of users which match a certain filter for the primary SMTP address in Microsoft Exchange 2010 and export this to a CSV file.

Firstly, I need to return all mailboxes for users matching my filter, in this example it is when the primary SMTP address can be like two domains.

Get-Mailbox | Where-Object {$_.PrimarySMTPAddress -like "*@domain1.com" -or $_.PrimarySMTPAddress -like "@domain2.com"}

Now, that I have all the mailboxes that match my filter I will pipe the output to the Get-MailboxStatistics cmdlet to return the Display Name and Total Item Size.

Get-MailboxStatistics | Select DisplayName, TotalItemSize

This will return the information I require, but the Total Item Size will be displayed in both MB and bytes.

DisplayName TotalItemSize
----------- -------------
User1       1.992 MB (2,088,411 bytes)

I am required to return the Total Item Size output in MB only, therefore I will be required to create an expression for the Total Item Size and convert the original value into MB.

@{expression={$_.TotalItemSize.Value.ToMB()}; label="TotalItemSizeMB"}

So lets put the full script together and export this to a CSV file.

Get-Mailbox | Where-Object {$_.PrimarySMTPAddress -like "*@domain1.com" -or $_.PrimarySMTPAddress -like "*@domain2.com"} | Get-MailboxDatabaseStatistics | Select DisplayName, @{expression={$_.TotalItemSize.ValueToMB(); label="TotalItemSizeMB"}