ITForum07 and LightsOut Exchange 2007 User Deployment

This morning I presented at ITForum and promised to post the Lights Out Scripts I used to install Ex2007 into an existing Ex2003 environment.

If you want the CSV's to go with it - then mail me. BrettjoATmicrosoftDOTcom

This is what it does:

1) Install Hub,CAS,MBX Ex2007 roles onto a member server into an existing 2003 Org

2) Delete default DB and SG

3) Creates numerous SG’s and DB’s

4) Mounts one of them

5) Enables LCR

6) Migrates users from 2003 to 2007

7) Copies 2003 mailboxes to a PST’s

8) Copies 2003 mailboxes inside a 2007 mailbox

9) Finishes successfully..! ;)

# Unplugged_Install.ps1
# Script will install Ex2007 SP1 into Ex2003 Org and move mailboxes to Ex2007
# Brettjo@Microsoft.com

&"C:\bin\Setup.com" "/r:M,C,H" "/LegacyRoutingServer:Ex2003SP2.Brettjo.local"

#####################################
#Adding the Exchange Snapin into Windows Powershell#
#####################################

Add-PsSnapin *Exchange*

################
#Adding the license key#
################

Set-ExchangeServer -id "LOEx2007SP1" -ProductKey: 12345-12345-12345-12345

###############
#Setting the variables#
###############

        $server = hostname
$Domain = "dc=Brettjo,dc=local"

###############
#Import the CSV files#
###############

$sgs = import-csv UnpluggedSG.csv
$mbxdbs = import-csv UnpluggedDBs.csv
$OUs = Import-csv UnpluggedOU.csv
$AllUsers = Import-csv UnpluggedUsers.csv

######################
#Create OU based on Database#
######################

        $OUs = Import-csv UnpluggedOU.csv
$objDomain = [ADSI]"LDAP://Ex2003SP2:389/OU=Unplugged,dc=Brettjo,dc=local"
foreach ($ou in $OUs) {
$objOU = $objDomain.Create("organizationalUnit", "ou=" + $ou.name)
$objOU.SetInfo()
}

############################
#Removing the pre-configured Databases#
############################

get-mailboxdatabase -id "$server\First Storage Group\Mailbox Database" | Dismount-Database -confirm:$false

        get-mailboxdatabase -id "$server\First Storage Group\Mailbox Database" | remove-mailboxdatabase -confirm:$false

        get-storagegroup -id "$server\First Storage Group" | remove-StorageGroup -confirm:$false

#################
#Database Management#
#################

$sgs = import-csv UnpluggedSG.csv
foreach ($sg in $sgs) {
new-storagegroup -Name $sg.Name -Server $server | ft Name,Server,ExchangeVersion
}

        $mbxdbs = import-csv UnpluggedDBs.csv
foreach ($mbxdb in $mbxdbs) {
new-mailboxdatabase -StorageGroup $mbxdb.StorageGroup -Name $mbxdb.Name | ft Name,Server,ExchangeVersion
}

        Get-MailboxDatabase -id "LOEx2007SP1\Unplugged_East\London" | mount-Database

###################
#Enable LCR on DB:London#
###################

MKDIR c:\LCR

        Enable-DatabaseCopy -Id 'LOEX2007SP1\Unplugged_East\London' -CopyEdbFilePath 'C:\LCR\London.edb'

        Enable-StorageGroupCopy -Id 'LOEX2007SP1\Unplugged_East' -CopyLogFolderPath 'C:\LCR' -CopySystemFolderPath 'C:\LCR'

##########################
#Moving Users from Ex2003 to Ex2007#
#                   #################################################
#All users are moved to Ex2007 except administrator whose mailbox is copied to a PST :) #
##########################################################

'Brettjo.local/Unplugged/Administrator' | move-mailbox -BadItemLimit '1' -TargetDatabase 'LOEX2007SP1\Unplugged_East\London' -GlobalCatalog 'Ex2003SP2.Brettjo.local' -DomainController 'Ex2003SP2.Brettjo.local' -confirm:$false

        'Brettjo.local/Unplugged/Eileen' | move-mailbox -BadItemLimit '1' -TargetDatabase 'LOEX2007SP1\Unplugged_East\London' -GlobalCatalog 'Ex2003SP2.Brettjo.local' -DomainController 'Ex2003SP2.Brettjo.local' -confirm:$false

        'Brettjo.local/Unplugged/Ewand' | move-mailbox -BadItemLimit '1' -TargetDatabase 'LOEX2007SP1\Unplugged_East\London' -GlobalCatalog 'Ex2003SP2.Brettjo.local' -DomainController 'Ex2003SP2.Brettjo.local' -confirm:$false

'Brettjo.local/Unplugged/Julian' | move-mailbox -BadItemLimit '1' -TargetDatabase 'LOEX2007SP1\Unplugged_East\London' -GlobalCatalog 'Ex2003SP2.Brettjo.local' -DomainController 'Ex2003SP2.Brettjo.local' -confirm:$false

'Brettjo.local/Unplugged/Markdea' | move-mailbox -BadItemLimit '1' -TargetDatabase 'LOEX2007SP1\Unplugged_East\London' -GlobalCatalog 'Ex2003SP2.Brettjo.local' -DomainController 'Ex2003SP2.Brettjo.local'

MKDIR C:\PSTs

Add-MailboxPermission -identity 'CN=Brettjo,OU=Unplugged,DC=Brettjo,DC=Local' -User 'Brettjo\Administrator' -AccessRights 'FullAccess' -confirm:$false

Add-MailboxPermission -identity 'CN=Julian,OU=Unplugged,DC=Brettjo,DC=Local' -User 'Brettjo\Administrator' -AccessRights 'FullAccess' -confirm:$false

Export-Mailbox -Id Brettjo@Brettjo.local -PSTFolderPath C:\PSTs\Brettjo.pst -confirm:$false

Export-Mailbox -Identity 'Brettjo.local/Unplugged/Brettjo' -TargetMailbox Julian@Brettjo.local -TargetFolder Brettjo_Mailbox -confirm:$false