Skip to content

Commit

Permalink
Merge pull request #593 from microsoft/main
Browse files Browse the repository at this point in the history
Release 5-19
  • Loading branch information
dpaulson45 authored May 19, 2021
2 parents 07588b2 + 1b100a0 commit 7109a6c
Show file tree
Hide file tree
Showing 22 changed files with 773 additions and 90 deletions.
10 changes: 6 additions & 4 deletions .build/CodeFormatter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ param(

#Requires -Version 7

if ($null -eq (Get-Module -Name PSScriptAnalyzer)) {
Install-Module -Name PSScriptAnalyzer -Force
. $PSScriptRoot\Load-Module.ps1

if (-not (Load-Module -Name PSScriptAnalyzer)) {
throw "PSScriptAnalyzer module could not be loaded"
}

if ($null -eq (Get-Module -Name EncodingAnalyzer)) {
Install-Module -Name EncodingAnalyzer -Force
if (-not (Load-Module -Name EncodingAnalyzer)) {
throw "EncodingAnalyzer module could not be loaded"
}

$repoRoot = Get-Item "$PSScriptRoot\.."
Expand Down
52 changes: 52 additions & 0 deletions .build/Load-Module.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function Load-Module {
[CmdletBinding()]
[OutputType([bool])]
param (
[Parameter(Mandatory = $true)]
[string]
$Name,

[Parameter(Mandatory = $false)]
[string]
$MinimumVersion
)

$moduleAlreadyLoaded = Get-Module -Name $Name
if ($null -ne $moduleAlreadyLoaded) {
if ([string]::IsNullOrEmpty($MinimumVersion) -or $moduleAlreadyLoaded.Version -ge $MinimumVersion) {
return $true
} else {
Remove-Module -Name $Name
}
}

$modulesOnDisk = @(Get-Module -Name $Name -ListAvailable | Sort-Object Version -Descending)
$moduleToLoad = $null
foreach ($module in $modulesOnDisk) {
if ([string]::IsNullOrEmpty($MinimumVersion) -or $module.Version -ge $MinimumVersion) {
$moduleToLoad = $module
break
}
}

if ($null -ne $moduleToLoad) {
Import-Module $moduleToLoad
return $true
}

$params = @{
Name = $Name
}

if (-not [string]::IsNullOrEmpty($MinimumVersion)) {
$params.MinimumVersion = $MinimumVersion
}

$errorCount = $Error.Count
Install-Module @params -Force
if ($Error.Count -gt $errorCount) {
return $false
}

return $true
}
8 changes: 7 additions & 1 deletion .build/Pester.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
$root = Get-Item "$PSScriptRoot\.."
. $PSScriptRoot\Load-Module.ps1

if (-not (Load-Module -Name Pester -MinimumVersion 5.2.0)) {
throw "Pester module could not be loaded"
}

$root = Get-Item "$PSScriptRoot\.."
$scripts = @(Get-ChildItem -Recurse $root |
Where-Object { $_.Name -like "*.Tests.ps1" }).FullName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
}

$osInformation.NetworkInformation.IPv6DisabledComponents = Invoke-RegistryGetValue -RegistryHive "LocalMachine" -MachineName $Script:Server -SubKey "SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" -GetValue "DisabledComponents" -CatchActionFunction ${Function:Invoke-CatchActions}
$osInformation.NetworkInformation.IPv6DisabledComponents = Get-RemoteRegistryValue -RegistryHive "LocalMachine" -MachineName $Script:Server -SubKey "SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" -GetValue "DisabledComponents" -ValueType "DWord" -CatchActionFunction ${Function:Invoke-CatchActions}
$osInformation.NetworkInformation.TCPKeepAlive = Invoke-RegistryGetValue -RegistryHive "LocalMachine" -MachineName $Script:Server -SubKey "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -GetValue "KeepAliveTime" -CatchActionFunction ${Function:Invoke-CatchActions}
$osInformation.NetworkInformation.RpcMinConnectionTimeout = Invoke-RegistryGetValue -RegistryHive "LocalMachine" -MachineName $Script:Server -SubKey "Software\Policies\Microsoft\Windows NT\RPC\" -GetValue "MinimumConnectionTimeout" -CatchActionFunction ${Function:Invoke-CatchActions}
$osInformation.NetworkInformation.HttpProxy = Get-HttpProxySetting
Expand Down
3 changes: 2 additions & 1 deletion Search/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.log
*.log
*.csv
23 changes: 20 additions & 3 deletions Search/Troubleshoot-ModernSearch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,18 @@ param(
$IsArchive,

[switch]
$IsPublicFolder
$IsPublicFolder,

[bool]
$ExportData = $true
)

#Not sure why yet, but if you do -Verbose with the script, we end up in a loop somehow.
#Going to add in this hard fix for the time being to avoid issues.
$Script:VerbosePreference = "SilentlyContinue"

$BuildVersion = ""

. $PSScriptRoot\Troubleshoot-ModernSearch\Exchange\Get-MailboxInformation.ps1

. $PSScriptRoot\Troubleshoot-ModernSearch\StoreQuery\Get-BasicMailboxQueryContext.ps1
Expand Down Expand Up @@ -110,16 +115,21 @@ Function Main {
"DocumentId: '$DocumentId'",
"MatchSubjectSubstring: '$MatchSubjectSubstring'",
"Category: '$Category'",
"GroupMessages: '$GroupMessages'",
"Server: '$Server'",
"SortByProperty: '$SortByProperty'",
"ExcludeFullyIndexedMailboxes: '$ExcludeFullyIndexedMailboxes'",
"QueryString: '$QueryString'",
"IsArchive: '$IsArchive'",
"IsPublicFolder: '$IsPublicFolder'") | Write-ScriptOutput -Diagnostic
"IsPublicFolder: '$IsPublicFolder'",
"ExportData: '$ExportData'"
) | Write-ScriptOutput -Diagnostic
Write-ScriptOutput "" -Diagnostic

if ($null -ne $Server -and
$Server.Count -ge 1) {

Write-MailboxStatisticsOnServer -Server $Server -SortByProperty $SortByProperty -ExcludeFullyIndexedMailboxes $ExcludeFullyIndexedMailboxes
Write-MailboxStatisticsOnServer -Server $Server -SortByProperty $SortByProperty -ExcludeFullyIndexedMailboxes $ExcludeFullyIndexedMailboxes -ExportData $ExportData
return
}

Expand Down Expand Up @@ -187,6 +197,12 @@ Function Main {
Write-ScriptOutput $messages[$i]
}

if ($ExportData) {
$filePath = "$PSScriptRoot\MessageResults_$ItemSubject_$(([DateTime]::Now).ToString('yyyyMMddhhmmss')).csv"
Write-ScriptOutput "Exporting Full Mailbox Stats out to: $filePath"
$messages | Export-Csv -Path $filePath
}

if (-not([string]::IsNullOrEmpty($QueryString))) {
$queryItemResults = Get-QueryItemResult -BasicMailboxQueryContext $basicMailboxQueryContext `
-DocumentId ($messages.MessageDocumentId) `
Expand Down Expand Up @@ -230,6 +246,7 @@ Function Main {
try {
Out-File -FilePath $Script:ScriptLogging -Force | Out-Null
Write-ScriptOutput "Starting Script At: $([DateTime]::Now)" -Diagnostic
Write-ScriptOutput "Build Version: $BuildVersion" -Diagnostic
Main
Write-ScriptOutput "Finished Script At: $([DateTime]::Now)" -Diagnostic
Write-Output "File Written at: $Script:ScriptLogging"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@

if ($_.DisplayName -notlike "SystemMailbox*" -and
$_.DisplayName -notlike "*HealthMailbox-*" -and
$_.MailboxTypeDetail.ToString() -ne "ArbitrationMailbox" -and
$_.DisconnectReason -eq $null) {

$totalMailboxItems = $_.ItemCount + $_.AssociatedItemCount + $_.DeletedItemCount
$totalBigFunnelItems = $_.BigFunnelIndexedCount + $_.BigFunnelPartiallyIndexedCount + $_.BigFunnelNotIndexedCount + `
$_.BigFunnelCorruptedCount + $_.BigFunnelStaleCount + $_.BigFunnelShouldNotBeIndexedCount
$totalBigFunnelSearchableItems = $totalBigFunnelItems - $_.BigFunnelShouldNotBeIndexedCount
$fullIndexPercentage = -1
$notPartIndexPercentage = -1

if ($totalBigFunnelSearchableItems -ne 0) {
$fullIndexPercentage = [Math]::Round((($_.BigFunnelIndexedCount / $totalBigFunnelSearchableItems) * 100), 2)
$notPartIndexPercentage = [Math]::Round((($_.BigFunnelIndexedCount / ($totalBigFunnelSearchableItems - $_.BigFunnelPartiallyIndexedCount)) * 100), 2)
}

$mailboxStatisticsList.Add([PSCustomObject]@{
Expand All @@ -46,6 +49,7 @@
TotalBigFunnelItems = $totalBigFunnelItems
TotalBigFunnelSearchableItems = $totalBigFunnelSearchableItems
FullyIndexPercentage = $fullIndexPercentage
IndexPercentage = $notPartIndexPercentage
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
IsPartiallyIndexed = "p{0:x}000B"
IsPermanentFailure = "p{0:x}000B"
LastIndexingAttemptTime = "p{0:x}0040"
DetectedLanguage = "p{0:x}0003"
DetectedLanguage = "p{0:x}001F"
}
}
process {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
} elseif ($Message.BigFunnelPOISize -gt 0 -and
$Message.BigFunnelPOISize -ne "NULL" -and
$Message.p3655000B -eq $true -and
($Message.($BigFunnelPropNameMapping.IsPartiallyIndexed) -eq "NULL" -or
($Message.($BigFunnelPropNameMapping.IsPartiallyIndexed).ToString() -eq "NULL" -or
$Message.($BigFunnelPropNameMapping.IsPartiallyIndexed) -eq $false)) {
$status = "Indexed"
} elseif ($Message.BigFunnelPOISize -gt 0 -and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Function Get-IndexingErrorMessage {
[CmdletBinding()]
param(
[object]$Message
)
begin {
$condensedErrorMessage = [string]::Empty
}
process {

if ($Message.MessageStatus -eq "Indexed") {
return
}

if (([string]::IsNullOrWhiteSpace($Message.IndexingErrorMessage)) -or
$Message.IndexingErrorMessage -eq "NULL") {

if (-not ([string]::IsNullOrWhiteSpace($Message.ErrorTags))) {
$condensedErrorMessage = $Message.ErrorTags
} else {
$condensedErrorMessage = "--Unknown--"
}
} elseif ($Message.IndexingErrorMessage -like "*Error parsing document exchange://localhost/Attachment*") {
$errorCode = $Message.IndexingErrorMessage.Substring(0, $Message.IndexingErrorMessage.IndexOf("Error parsing")).Trim()
$condensedErrorMessage = "Error parsing document: $errorCode"
} else {
$condensedErrorMessage = $Message.IndexingErrorMessage
}
}
end {
return $condensedErrorMessage
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
. $PSScriptRoot\Get-IndexStateOfMessage.ps1
. $PSScriptRoot\Get-IndexingErrorMessage.ps1
. $PSScriptRoot\Get-MessageInformationObject.ps1
Function Get-MailboxIndexMessageStatistics {
[CmdletBinding()]
param(
Expand Down Expand Up @@ -37,6 +38,8 @@ Function Get-MailboxIndexMessageStatistics {
$storeQueryHandler.SetSelect(@(
"MessageId",
"MessageDocumentId",
"Size",
"HasAttachments",
"MessageClass",
"p0E1D001F",
"p1035001F",
Expand All @@ -48,8 +51,6 @@ Function Get-MailboxIndexMessageStatistics {
$storeQueryHandler.SetFrom("Message")
$storeQueryHandler.SetWhere("MailboxNumber = $mailboxNumber AND FolderId != $conversationFolderId")

$messageStatus = "Unknown"

switch ($Category) {
"All" {
#Do Nothing
Expand All @@ -58,33 +59,27 @@ Function Get-MailboxIndexMessageStatistics {
$storeQueryHandler.AddToWhere(" AND (BigFunnelPoiNotNeededReason = NULL or BigFunnelPoiNotNeededReason <= 0)")
$storeQueryHandler.AddToWhere(" AND (BigFunnelPOISize > 0) AND (BigFunnelPOIIsUpToDate = true)")
$storeQueryHandler.AddToWhere(" AND ($($extPropMapping.IsPartiallyIndexed) = null or $($extPropMapping.IsPartiallyIndexed) = false)")
$messageStatus = "Indexed"
}
"PartiallyIndexed" {
$storeQueryHandler.AddToWhere(" AND (BigFunnelPoiNotNeededReason = NULL or BigFunnelPoiNotNeededReason <= 0)")
$storeQueryHandler.AddToWhere(" AND (BigFunnelPOISize > 0) and (BigFunnelPOIIsUpToDate = true)")
$storeQueryHandler.AddToWhere(" AND $($extPropMapping.IsPartiallyIndexed) = true")
$messageStatus = "PartiallyIndexed"
}
"NotIndexed" {
$storeQueryHandler.AddToWhere(" AND (BigFunnelPoiNotNeededReason = NULL or BigFunnelPoiNotNeededReason <= 0)")
$storeQueryHandler.AddToWhere(" AND (BigFunnelPOISize = NULL or BigFunnelPOISize <= 0)")
$storeQueryHandler.AddToWhere(" AND (BigFunnelPOIIsUpToDate = NULL or BigFunnelPOIIsUpToDate = false)")
$messageStatus = "NotIndexed"
}
"Corrupted" {
$storeQueryHandler.AddToWhere(" AND (BigFunnelPoiNotNeededReason = NULL or BigFunnelPoiNotNeededReason <= 0)")
$storeQueryHandler.AddToWhere(" AND (BigFunnelPOISize = NULL or BigFunnelPOISize <= 0) and (BigFunnelPOIIsUpToDate = true)")
$messageStatus = "Corrupted"
}
"Stale" {
$storeQueryHandler.AddToWhere(" AND (BigFunnelPoiNotNeededReason = NULL or BigFunnelPoiNotNeededReason <= 0)")
$storeQueryHandler.AddToWhere(" AND (BigFunnelPOISize > 0) and (BigFunnelPOIIsUpToDate = NULL or BigFunnelPOIIsUpToDate = false)")
$messageStatus = "Stale"
}
"ShouldNotBeIndexed" {
$storeQueryHandler.AddToWhere(" AND (BigFunnelPoiNotNeededReason > 0)")
$messageStatus = "ShouldNotBeIndexed"
}
}

Expand All @@ -98,30 +93,13 @@ Function Get-MailboxIndexMessageStatistics {
}

for ($i = 0; $i -lt $messages.Count; $i++) {
$message = $messages[$i]

if ($Category -eq "All") {
$messageStatus = Get-IndexStateOfMessage -Message $message -BigFunnelPropNameMapping $extPropMapping
}
$messageInformationObject = Get-MessageInformationObject -StoreQueryMessage $messages[$i] `
-BigFunnelPropNameMapping $extPropMapping

$messageInformationObject | Add-Member -MemberType NoteProperty -Name "CondensedErrorMessage" -Value (Get-IndexingErrorMessage -Message $messageInformationObject)

$messageList.Add(
[PSCustomObject]@{
MessageId = $message.MessageId
InternetMessageId = $message.p1035001F
MessageDocumentId = $message.MessageDocumentId
MessageClass = $message.MessageClass
Subject = $message.p0E1D001F
BigFunnelPOISize = $message.BigFunnelPOISize
BigFunnelPOIIsUpToDate = $message.p3655000B
BigFunnelPoiNotNeededReason = $message.p365A0003
IsPartiallyIndexed = $message."$($extPropMapping.IsPartiallyIndexed)"
IndexingErrorCode = $message."$($extPropMapping.IndexingErrorCode)"
IndexingErrorMessage = $message."$($extPropMapping.IndexingErrorMessage)"
LastIndexingAttemptTime = $message."$($extPropMapping.LastIndexingAttemptTime)"
IndexingAttemptCount = $message."$($extPropMapping.IndexingAttemptCount)"
IsPermanentFailure = $message."$($extPropMapping.IsPermanentFailure)"
MessageStatus = $messageStatus
})
$messageList.Add($messageInformationObject)
}
}
end {
Expand Down
Loading

0 comments on commit 7109a6c

Please sign in to comment.