Created
November 15, 2021 16:28
-
-
Save jpomfret/a9afa22c4d1129fecc4ea3e6cde1b51c to your computer and use it in GitHub Desktop.
Script to combine index usages stats across multiple AG nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$PrimaryInstance = 'Sql1' | |
$SecondaryInstance = 'Sql2' | |
$SqlInstance = $PrimaryInstance, $SecondaryInstance | |
$Database = 'DbName' | |
$results = Get-DbaHelpIndex -SqlInstance $SqlInstance -Database $Database | |
$export = @() | |
$export += $results | Where-Object {$_.SqlInstance -eq $PrimaryInstance} | ForEach-Object -PipelineVariable pIndex -Process { $_ } | ForEach-Object { | |
# get the matching secondary row | |
$sIndex = $results | Where-Object { $_.SqlInstance -eq $SecondaryInstance -and $_.ObjectName -eq $pIndex.ObjectName -and $_.Index -eq $pIndex.Index} | |
[PSCustomObject]@{ | |
PrimaryInstance = $pIndex.SqlInstance | |
SecondaryInstance = $sIndex.SqlInstance | |
Database = $pIndex.Database | |
Object = $pIndex.Object | |
Index = $pIndex.Index | |
IndexType = $pIndex.IndexType | |
KeyColumns = $pIndex.KeyColumns | |
IncludeColumns = $pIndex.IncludeColumns | |
FilterDefinition = $pIndex.FilterDefinition | |
Rows = $pIndex.IndexRows | |
SizeKB = $pIndex.Size | |
PrimaryIndexReads = [int]$pIndex.IndexReads | |
SecondaryIndexReads = [int]$sIndex.IndexReads | |
TotalIndexReads = [int]$pIndex.IndexReads + $sIndex.IndexReads | |
PrimaryIndexUpdates = [int]$pIndex.IndexUpdates | |
SecondaryIndexUpdates = [int]$sIndex.IndexUpdates | |
TotalIndexUpdates = [int]$pIndex.IndexUpdates + $sIndex.IndexUpdates | |
} | |
} | |
$export | Export-Excel -Path IndexUsage.xlsx -WorksheetName IndexUsage -TableName IndexUsage -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment