Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active December 30, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/16cb823a6e58d5aa4ad86edb72d32b7b to your computer and use it in GitHub Desktop.
Save bill-long/16cb823a6e58d5aa4ad86edb72d32b7b to your computer and use it in GitHub Desktop.
param($Database, $SaveResults)
. $exscripts\ManagedStoreDiagnosticFunctions.ps1
if ($null -eq (Get-Command Get-StoreQuery -ErrorAction SilentlyContinue)) {
Write-Error "ManagedStoreDiagnosticFunctions not loaded."
return
}
$results = @()
$mailboxes = Get-StoreQuery -Database $Database -Query "Select MailboxNumber,DisplayName from Mailbox" -Unlimited
$count = 0
$mailboxes | ForEach-Object {
$count++
Write-Progress -Activity "Counting indexes" -PercentComplete ($count * 100 / $mailboxes.Count) -CurrentOperation $_.DisplayName
$indexes = @(Get-StoreQuery -Database $Database -Query "Select * from PseudoIndexControl where MailboxPartitionNumber = $($_.MailboxNumber)" -Unlimited)
$outputObject = [PSCustomObject]@{
MailboxNumber = $_.MailboxNumber
DisplayName = $_.DisplayName
IndexCount = $indexes.Count
}
$results += $outputObject
$outputObject
}
$results = $results | Sort-Object MailboxNumber
$timeString = [DateTime]::Now.ToString("yyyyMMddHHmmss")
$fileName = "PhysicalIndexCount-$timeString.csv"
if ($SaveResults) {
$results | Export-Csv "$PSScriptRoot\$fileName" -NoTypeInformation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment