?
Solved

Enable email Archiving powershell script

Posted on 2013-12-15
11
Medium Priority
?
2,563 Views
Last Modified: 2016-06-17
I have a list users  with alias name in  a text file. I want a script which can check which user database the user mailbox is on and depending on that create a archive mailbox for that user. Also apply a retension policy for that user.

Example: User1 is  either on maildatabase1 or maildatabase2 need to enable archiving on archivedatabase1 and need to enable retention policy

maildatabase3 or maildatabase4 ->archivedatabase2 and so on
0
Comment
Question by:Malli Boppe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
11 Comments
 
LVL 53

Assisted Solution

by:Will Szymkowski
Will Szymkowski earned 664 total points
ID: 39722000
I have created a script for accomplishing the above question. See below script for details...

The script below has variables that need to match up with your database names and archive database names below.

Import-Module activedirectory
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
$MBXDB1 = Write-Host "MailboxDataBase1"
$MBXDB2 - Write-Host "MailboxDatabase2"
$Archive1 = Write-Host "MailboxArchive1"
$Archive2 = Write-Host "MailboxArchive2"
$UsersList = Get-Content "c:\yourFILEhere.txt"
foreach ($User in $UserList) {
$User.Alias
Get-MailboxStatistics -Identity $User.Alias
    if ($_.Datbase -eq $MBXDB1) {
        Get-Mailbox -Name $User.Alias | New-Mailbox -Archive -ArchiveDatabase $Archive1
    } or {
    if ($_.Database -eq $MBXDB2) {
        Get-Mailbox -Name $User.Alias | New-Mailbox -Archive -ArchiveDatabase $Archive2
        }
    }
}

Open in new window

Will.
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 1336 total points
ID: 39722204
Spec01,

Get-Mailbox should provide you with the Database value already, so no need to use Get-MailBoxStatistics, And the AD module isn't used here, so no need to import that.
Also, setting the vars doesn't make sense as you do here, Write-Host doesn't return anything.
And the IF syntax is wrong, too.

My (untested) suggestion is:
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin

Get-Content "C:\Users.csv" | Get-Mailbox | % {
  if ("maildatabase1", "maildatabase2" -contains $_.Database)
  { $arcDb = "archivedatabase1" }
  elseif ("maildatabase3", "maildatabase4" -contains $_.Database)
  { $arcDb = "archivedatabase2" }
  # and so on
  $_ | New-Mailbox -Archive -ArchiveDatabase $arcDb
}

Open in new window

This could be done somewhat more elegant with a switch. You also might have to supply the -RetensionPolicy parameter when creating the archive mailbox to enable it, but what to provide with that is determined by your Exchange settings.
0
 
LVL 23

Author Comment

by:Malli Boppe
ID: 39723251
Thanks Guys, the below script  works for a single user but when the CSV file has multiple users throws up an error "Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently"

Get-Content "C:\temp\Users.csv" | Get-Mailbox | % {
  if ("mailbox database1", "mailbox database2" -contains $_.Database)
  { $arcDb = "archive database1" }
  elseif ("mailbox database3", "mailbox database4" -contains $_.Database)
  { $arcDb = "archive database2" }
elseif ("mailbox database5", "mailbox database6" -contains $_.Database)
  { $arcDb = "archive database3" }

  $_ | enable-Mailbox -Archive -ArchiveDatabase $arcDb
 $_ | Set-mailbox -RetentionPolicy "90 Day Archive - All Mail Folders (Never Delete)"
}

Open in new window

0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 1336 total points
ID: 39723727
Try if this helps:
  Enable-Mailbox -Identity $_.Identity -Archive -ArchiveDatabase $arcDb
  Set-mailbox -Identity $_.Identity -RetentionPolicy "90 Day Archive - All Mail Folders (Never Delete)"

Open in new window

0
 
LVL 23

Author Comment

by:Malli Boppe
ID: 39725827
This is what I had to do
$list=Get-Content "C:\temp\Users.csv" | Get-Mailbox

$list  | % {
  if ("mailbox database1", "mailbox database2" -contains $_.Database)
  { $arcDb = "archive database1" }
  elseif ("mailbox database3", "mailbox database4" -contains $_.Database)
  { $arcDb = "archive database2" }
elseif ("mailbox database5", "mailbox database6" -contains $_.Database)
  { $arcDb = "archive database3" }


Enable-Mailbox -Identity $_.Identity -Archive -ArchiveDatabase $arcDb
Set-mailbox -Identity $_.Identity -RetentionPolicy "90 Day Archive - All Mail Folders (Never Delete)"
 }

Open in new window

1
 
LVL 71

Expert Comment

by:Qlemo
ID: 39726084
So my last change works, or do you really need to have fetched all mailboxes before going into the processing pipeline?
0
 
LVL 23

Author Comment

by:Malli Boppe
ID: 39727943
Yeah your last changes and  I have changed the first few lines to make it work
0
 

Expert Comment

by:Member_2_7965358
ID: 41658633
In addition to this script (Malli's last one) worked really well... I'd like to add a couple of pieces to the puzzle.

Is there an easy way to add the Quota Limit and Quota Warning?

Again, great script!

Ed Resleff
0
 

Expert Comment

by:Member_2_7965358
ID: 41658709
Thanks for the advice... But, I've already found the answer.

Ed
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
This video discusses moving either the default database or any database to a new volume.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

718 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