Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PublicFolders/SourceSideValidations/Get-FolderData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Get-FolderData {
$folderData.Statistics | Export-Csv $PSScriptRoot\Statistics.csv
foreach ($errorParam in $statisticsResult.Errors) {
$errorResult = New-TestResult @errorParam
$folderData.Errors.Add($errorResult)
$null = $folderData.Errors.Add($errorResult)
}
}
}
Expand Down
48 changes: 31 additions & 17 deletions PublicFolders/SourceSideValidations/Get-Statistics.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,36 @@ function Get-Statistics {
if ($null -eq $FolderData) {
$WarningPreference = "SilentlyContinue"
Import-PSSession (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$Server/powershell" -Authentication Kerberos) | Out-Null
$statistics = Get-PublicFolderStatistics -ResultSize Unlimited | ForEach-Object {
$progressCount++
if ($sw.ElapsedMilliseconds -gt 1000) {
$sw.Restart()
Write-Progress @progressParams -Status $progressCount
}
for ($i = 0; $i -lt 3; $i++) {
try {
$statistics = Get-PublicFolderStatistics -ResultSize Unlimited | ForEach-Object {
$progressCount++
if ($sw.ElapsedMilliseconds -gt 1000) {
$sw.Restart()
Write-Progress @progressParams -Status $progressCount
}

[Int64]$totalItemSize = -1
if ($_.TotalItemSize.ToString() -match "\(([\d|,|.]+) bytes\)") {
$numberString = $Matches[1] -replace "\D", ""
$totalItemSize = [Int64]::Parse($numberString)
}
[Int64]$totalItemSize = -1
if ($_.TotalItemSize.ToString() -match "\(([\d|,|.]+) bytes\)") {
$numberString = $Matches[1] -replace "\D", ""
$totalItemSize = [Int64]::Parse($numberString)
}

[PSCustomObject]@{
EntryId = $_.EntryId
ItemCount = $_.ItemCount
TotalItemSize = $totalItemSize
[PSCustomObject]@{
EntryId = $_.EntryId
ItemCount = $_.ItemCount
TotalItemSize = $totalItemSize
}
}
} catch {
Write-Warning "Failed to get statistics from $Server. Attempt $($i + 1) of 3."
Write-Verbose "Exception: $($_.Exception.Message)"
if ($i -eq 2) {
Write-Error "Failed to get statistics from $Server after 3 attempts. Exception: $($_.Exception)"
return
} else {
Start-Sleep -Seconds 5
}
}
}
} else {
Expand Down Expand Up @@ -100,7 +113,7 @@ function Get-Statistics {

$hierarchyMailbox = Get-Mailbox -PublicFolder (Get-OrganizationConfig).RootPublicFolderMailbox.ToString()
$serverWithHierarchy = (Get-MailboxDatabase $hierarchyMailbox.Database).Server.Name
$retryJobNumber = 1
$retryJobNumber = 0

Wait-QueuedJob | ForEach-Object {
$finishedJob = $_
Expand All @@ -119,9 +132,10 @@ function Get-Statistics {
$foldersRemaining = @($finishedJob.Folders | Where-Object { -not $entryIdsProcessed.Contains($_.EntryId) })
if ($foldersRemaining.Count -gt 0) {
Write-Host "$($foldersRemaining.Count) folders remaining in the failed job. Re-queueing for $serverWithHierarchy."
$retryJobNumber++
$retryJob = @{
ArgumentList = $serverWithHierarchy, $hierarchyMailbox.Name, $foldersRemaining
Name = "Statistics Retry Job $($retryJobNumber++)"
Name = "Statistics Retry Job $($retryJobNumber)"
ScriptBlock = ${Function:Get-StatisticsJob}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ param (
# For HashSet support
Add-Type -AssemblyName System.Core -ErrorAction Stop

$BuildVersion = ""

try {
if (-not $SkipVersionCheck) {
if (Test-ScriptVersion -AutoUpdate) {
Expand Down Expand Up @@ -234,12 +236,10 @@ try {
Write-Host
Write-Host "Validation results were written to file:"
Write-Host $ResultsFile -ForegroundColor Green

$private:endTime = Get-Date

Write-Host
Write-Host "SourceSideValidations complete. Total duration" ($endTime - $startTime)
} finally {
$private:endTime = Get-Date
Write-Host "SourceSideValidations $BuildVersion complete. Total duration" ($endTime - $startTime)
Write-Host
Write-Host "Liked the script or had a problem? Let us know at ExToolsFeedback@microsoft.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ function Test-MailEnabledFolder {

begin {
function GetCommandToMergeEmailAddresses($publicFolder, $orphanedMailPublicFolder) {
$linkedMailPublicFolder = Get-PublicFolder $publicFolder.Identity | Get-MailPublicFolder
$linkedMailPublicFolder = Get-PublicFolder $publicFolder.Identity | Get-MailPublicFolder -ErrorAction SilentlyContinue
if ($null -eq $linkedMailPublicFolder) {
return $null
}

$emailAddressesOnGoodObject = @($linkedMailPublicFolder.EmailAddresses | Where-Object { $_.ToString().StartsWith("smtp:", "OrdinalIgnoreCase") } | ForEach-Object { $_.ToString().Substring($_.ToString().IndexOf(':') + 1) })
$emailAddressesOnBadObject = @($orphanedMailPublicFolder.EmailAddresses | Where-Object { $_.ToString().StartsWith("smtp:", "OrdinalIgnoreCase") } | ForEach-Object { $_.ToString().Substring($_.ToString().IndexOf(':') + 1) })
$emailAddressesToAdd = $emailAddressesOnBadObject | Where-Object { -not $emailAddressesOnGoodObject.Contains($_) }
Expand Down Expand Up @@ -164,8 +168,11 @@ function Test-MailEnabledFolder {
$partialEntryId += "0000"
if ($byPartialEntryId.TryGetValue($partialEntryId, [ref]$pf)) {
if ($pf.MailEnabled -eq $true) {

$command = GetCommandToMergeEmailAddresses $pf $thisMPF
if ($mailPublicFoldersLinked.ContainsKey($_.Guid.ToString())) {
$command = GetCommandToMergeEmailAddresses $pf $thisMPF
} else {
$command = "Set-PublicFolder `"$($pf.Identity)`" -MailRecipientGuid $($thisMPF.Guid)"
}

$params = @{
Identity = $thisMPF.DistinguishedName.Replace("/", "\/")
Expand Down
Loading