Enable Exchange 2010 Online Archive in a mixed environment (Part 1: By OU)
- Part 2: Enable Exchange 2010 Online Archive in a mixed environment by Database
- Part 3: Enable Exchange 2010 Online Archive in a mixed environment by CSV
- Part 4: Conclusion (all wrapped up)
Hello! Today I am going to show you how to enable the Exchange 2010 online archive in a mixed (2007/2010) environment, by OU. Long title, I know! Here is what we’re working with..
- Mixed environment
- Enable based on OU
- Split online archives amongst 4 different databases
What it does
This function will get users from a specific OU, ensure they are Exchange 2010 users, and enable the online archive while spreading the users across four seperate databases.
What you need and need to know
- No special considerations for this!
Learn it
As in previous topics, we will use ConnectAD and ConnectExchange to load these modules remotely rather than depend on having the tools installed locally.
1 2 3 4 5 6 7 8 9 10 11 12 |
#Connect to Active Directory and load modules function ConnectAD { $session = New-PSSession -ComputerName $dc Invoke-Command -Session $session -ScriptBlock {Import-Module ActiveDirectory} Import-PSSession -Session $session -Module ActiveDirectory } #Connect to Exchange and load modules function ConnectExchange { $exch = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$exchangefqdn/powershell -name Exchange Import-PSSession $exch } |
Load the modules (AD and Exchange), unless they have already been loaded.
1 2 3 4 5 6 7 8 |
#Load modules if(!(Get-PSSession | ?{$_.ComputerName -like "$dc*"}) -and $askoncepersessionmodules -ne 1) { $global:askoncepersessionmodules = 1 cls write-host "Connecting to Active Directory, and Exchange. Please wait..." -f yellow; ConnectAD ConnectExchange } |
We need to set our variables.
1 2 3 4 5 6 7 8 9 10 |
# Domain controller FQDN $dc = "dc.domain.local" # Exchange FQDN $exchangefqdn = "exch.domain.local" # Online Archive databases $databases = "DB1", "DB2", "DB3", "DB4" # OU of users you want to enable $ou = "ou=Users,ou=Location,dc=domain,dc=local" # Your full Exchange version. If you don't know, type (get-mailbox user).ExchangeVersion $exchangeversion = "0.10 (14.0.100.0)" |
We’re now ready to enable the online archive.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#Enable online Archive by OU function EnableOnlineArchiveOU { $count = 0 # Get users in specific OU $users = Get-ADUser -filter * -SearchBase "$ou" | Sort Name foreach($user in $users) { # Get mailbox based on the users full name $mailbox = Get-Mailbox $user.name # Is this user on Exchange 2010? if($mailbox.ExchangeVersion -like "0.10 (14.0.100.0)") { # Enable the mailbox. We take a database from the $databases array, and select the next database based on $count enable-mailbox $mailbox.alias -Archive -ArchiveDatabase $databases[$count] $count++ # When $count reaches the number of databases in your array, reset $count to 0 if($count -eq $databases.count) { $count = 0; } } } } |
I hope this post is useful to you, and thank you for reading.
Download ZIP
[wpdm_file id=2]Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
######################################## # Enable Online Archive by OU # Created by Troy Ward ######################################## #Variables # Domain controller FQDN $dc = "dc.domain.local" # Exchange FQDN $exchangefqdn = "exch.domain.local" # Online Archive databases $databases = "DB1", "DB2", "DB3", "DB4" # OU of users you want to enable $ou = "ou=Users,ou=Location,dc=domain,dc=local" # Your full Exchange version. If you don't know, type (get-mailbox user).ExchangeVersion $exchangeversion = "0.10 (14.0.100.0)" # No more variables #Connect to Active Directory and load modules function ConnectAD { $session = New-PSSession -ComputerName $dc Invoke-Command -Session $session -ScriptBlock {Import-Module ActiveDirectory} Import-PSSession -Session $session -Module ActiveDirectory } #Connect to Exchange and load modules function ConnectExchange { $exch = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$exchangefqdn/powershell -name Exchange Import-PSSession $exch } #Load modules if(!(Get-PSSession | ?{$_.ComputerName -like "$dc*"}) -and $askoncepersessionmodules -ne 1) { $global:askoncepersessionmodules = 1 cls write-host "Connecting to Active Directory, and Exchange. Please wait..." -f yellow; ConnectAD ConnectExchange } #Enable online Archive by OU function EnableOnlineArchiveOU { $count = 0 # Get users in specific OU $users = Get-ADUser -filter * -SearchBase "$ou" | Sort Name foreach($user in $users) { # Get mailbox based on the users full name $mailbox = Get-Mailbox $user.name # Is this user on Exchange 2010? if($mailbox.ExchangeVersion -like "$exchangeversion") { # Enable the mailbox. We take a database from the $databases array, and select the next database based on $count enable-mailbox $mailbox.alias -Archive -ArchiveDatabase $databases[$count] $count++ # When $count reaches the number of databases in your array, reset $count to 0 if($count -eq $databases.count) { $count = 0; } } } } EnableOnlineArchiveOU |