Tuesday, May 28, 2013

Compare Source and Target Mailbox Size–PowerShell Script

This PowerShell script can be used to compare source (Exchange 2003) and target (exchange 2007/2010) mailbox size.  This script is useful when performing a mailbox migration

Script:

#
# This script can be used to compare Source and Target mailbox data
# Author - Santhosh Sivarajan
# Verion 1.1
#
Clear
$SExServer = "houex01.sivarajan1.com"
$TExserver = "etmrex01.sivarajan2.com"
$Output = New-item -type file -force "D:\Scripts\MailStats.txt"
"DisplayName`tAlias`tSourceTotalItem`tTargetTotalItem`tSourceSize(KB)`tTargetSize(MB)" | Out-File $Output -append -encoding ASCII
$scred = Get-Credential
clear
Write-host "Alias`t`tSourceTotalItem`tTargetTotalItem`tSourceSize(KB)`tTargetSize(MB)"
Import-CSV D:\Scripts\Mailboxinput.csv | % {
#Mailboxinput.csv file header -> MailAlias
    $Alias = $_.MailAlias
    $tAlias = ""
    $Ssize = ""
    $Stotalitem = ""
    $TtempResult = ""
    $Ttotalitem = ""
    $Tsize = ""
#Searching AD to get Dispaly Name
    $ObjFilter = "(&(objectCategory=person)(objectCategory=User)(mailnickname=$Alias))"
    $objSearch = New-Object System.DirectoryServices.DirectorySearcher
    $objSearch.PageSize = 5000
    $objSearch.Filter = $ObjFilter 
    $objSearch.SearchRoot = "LDAP://DC=sivarajan2,DC=com"
    $AllObj = $objSearch.findone()
    $user = [ADSI] $AllObj.path
    $objItemT = $user.Properties
    $tAlias = $objItemT.DisplayName
    #Write-host "Searching..." $tAlias
#Searching source EX
    $Stempresult = get-wmiobject -namespace root\MicrosoftExchangev2 -class Exchange_mailbox -computer $SExServer  -Filter "MailboxDisplayName = '$tAlias'" -

Credential $scred
    $Ssize = $Stempresult.size
    $Stotalitem = $Stempresult.TotalItems
#searching target EX
    $TtempResult = Get-MailboxStatistics -Identity "$Alias"
    $Ttotalitem = $TtempResult.ItemCount
    $Tsize = $TtempResult.TotalItemSize.value
    Write-host $Alias`t`t$Stotalitem`t$Ttotalitem`t$Ssize`t$Tsize
    $tAlias+"`t"+$Alias+"`t"+ $Stotalitem+"`t"+ $Ttotalitem+"`t"+$Ssize+"`t"+$Tsize | Out-File $output -append -encoding ASCII
    }

 

Download:

___________________________________________________________________________________________

Migrating from Windows Server 2008 or Windows Server 2008 R2 to Windows Sever 2012?

Paperback - http://www.amazon.com/dp/1849687447/?tag=packtpubli-20

eBook - http://www.packtpub.com/migrating-from-2008-and-2008-r2-to-windows-server-2012/book

___________________________________________________________________________________________

1 comments:

It was nice to find this post. I will learn more about this script. Thanks!

Post a Comment

Popular Posts

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More