Solved

Enable email Archiving powershell script

Posted on 2013-12-15
11
2,151 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
  • 3
  • 3
  • 2
  • +1
11 Comments
 
LVL 53

Assisted Solution

by:Will Szymkowski
Will Szymkowski earned 166 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 68

Accepted Solution

by:
Qlemo earned 334 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
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 334 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
Make managing Office 365 email signatures a breeze

Are you using Office 365? Having trouble trying to set up email signatures for your users? Getting stressed out managing multiple signatures? Need an easier way to manage? We have a solution for you, try the most-user friendly and powerful signature management tool on the market.

 
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 68

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

895 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

15 Experts available now in Live!

Get 1:1 Help Now