#------------------------------------------------------------------------- # pfreplcheck.vbs # # Description # Loads public folder statistics from Exchange 2007 (PS) and Exchange 2003 (WMI) # compares itemcount to find folders out of sync during migration # # You have to specify the server name and the type as the part of the code # # the script uses the credentials of the executing user. # - You need approbiate permissions to run the commandlet "get-publicfolderstatistics" # - Make sure that you are running the script ona box with Powershell 1.0 and exchange management components # - marke sure you are able to do a WMI conect # # (c)2009 Net at Work Netzwerksysteme GmbH # # Version 1.0-1.2 (09 Apr. 2009) Frank Carius # Initial Release build with a customer. never made public. # Version 1.3 (09 Apr. 2009) Frank Carius # First public version with sample server names and better debugging # # Stept to use that script # Start Exchange Management shell # modify the script to use the server names and type # $dict1 = get2007pflist hermes # $dict2 = get2003pflist 3r2-hermes1 # Execute witrh .\pfreplcheck.1.2.ps1 | Export-Csv -Path .\pf.csv # #------------------------------------------------------------------------- function get2007pflist {param($server) # Loads Exchange 2007 public Folder statistics and returns a normalized hashtable Write-Host "get2007pflist start" $folderlist = get-publicfolderstatistics -server $server Write-Host "get2007pflist Found " $folderlist.count " folders" $dict = @{} $folderlist | % { if ($_.folderpath -ne $null) { Write-Host " Processing:" $_.folderpath $normalpath = "/".insert(0,$_.folderpath.replace("\","/").insert(0,"/")) Write-Host " Processing:" $normalpath $dict.add($normalpath,@{itemcount = $_.itemcount; foldersize = $_.TotalItemSize.value.tobytes()}) } else { Write-Warning -Message ("Skipping " + $_.name + " with empty folderpath") } } Write-Output $dict Write-Host "get2007pflist end" } function get2003pflist {param($server) # Loads Exchange 2003 public Folder statistics and returns a normalized hashtable Write-Host "get2003pflist start" $folderlist = Get-WmiObject -ComputerName $server -namespace "root\MicrosoftExchangeV2" -class "Exchange_PublicFolder" Write-Host "get2003pflist Found " $folderlist.count " folders" $dict = @{} $folderlist | % { Write-Host " Processing:" $_.path $dict.add($_.path,@{itemcount = $_.messagecount; foldersize = $_.normalmessagesize}) } Write-Output $dict Write-Host "get2007pflist end" } Write-Host "PFreplCheck start" Write-Host "Loading Exchange 2007 Public Folder List" #$dict1 = @{} $dict1 = get2007pflist nawsv002 Write-Host "Loading Exchange 2003 Public Folder List" #$dict2 = @{} $dict2 = get2003pflist nawsv001 Write-Host "Comparing DICT1 with DICT2" foreach ($folder in $dict1.keys) { Write-Verbose "Processing dict1 $folder" $result = New-Object PSObject Add-Member -InputObject $result noteproperty "path" $folder Add-Member -InputObject $result noteproperty "s1count" $dict1.Get_Item($folder).itemcount Add-Member -InputObject $result noteproperty "s1size" $dict1.Get_Item($folder).foldersize if ($dict2.ContainsKey($folder)) { Write-Verbose " Patch found. Checking content" Add-Member -InputObject $result noteproperty "s2count" $dict2.Get_Item($folder).itemcount Add-Member -InputObject $result noteproperty "s2size" $dict2.Get_Item($folder).foldersize if ($result.s1count -eq $result.s2count){ Write-Host "Folder $folder.path identical" Add-Member -InputObject $result noteproperty "status" "consistent" } else { Write-warning "Folder $folder not identical" Add-Member -InputObject $result noteproperty "status" "different" } #remove processed entry #$dict1.remove($folder) # not allowed because foreach enumeration will be changed $dict2.remove($folder) } else { Write-Warning "Folder $folder not found on System 2 - not replicated ?" Add-Member -InputObject $result noteproperty "status" "missing in 2" } Write-Output $result } Write-Host "Checking unmatched folders in dict2" foreach ($folder in $dict2.keys) { write-warning "Folder $folder not existing on System 1 - not replicated" $result = New-Object PSObject Add-Member -InputObject $result noteproperty "path" $folder Add-Member -InputObject $result noteproperty "s2count" $dict2.Get_Item($folder).itemcount Add-Member -InputObject $result noteproperty "s2size" $dict2.Get_Item($folder).foldersize Add-Member -InputObject $result noteproperty "status" "missing in 1" Write-Output $result } Write-Host "PFreplCheck end"