From the Distribution worksheet of the spreadsheet, I populated an array with each of the possible values. This is the activation preference, in order, with null columns equal to 0.
$DBDistro = @('123000','012300','001230','000123','300012','230001','102300',`
'010230','001023','300102','230010','023001','100230','010023',`
'301002','230100','023010','002301','100023','310002','231000',`
'023100','002310','000231','130002','213000','021300','002130',`
'000213','300021','120300','012030','001203','300120','030012',`
'203001','102030','010203','301020','030102','203010','020301',`
'100203','310020','031002','203100','020310','002031')
Then when I run the script against a specific DAG, it tells me if DBs are correctly in alignment and which ones are not.
[PS] PS:\>.\Report-DAGAPDistribution.ps1 dag3
ERROR: Bad Activation Preference - SHARED-DB05 is 003021
123000 ADMIN-DB01
012300 ADMIN-DB02
001230 ADMIN-DB03
000123 ADMIN-DB04
300012 ADMIN-DB05
230001 ADMIN-DB06
102300 ADMIN-DB07
010230 ADMIN-DB08
001023 WAREHOUSE-DB01
300102 WAREHOUSE-DB02
230010 WAREHOUSE-DB03
023001 CIO-DB01
100230 CIO-DB02
010023 CIO-DB03
301002 CIO-DB04
230100 CIO-DB05
023010 CIO-DB06
002301 CIO-DB07
100023 CIO-DB08
310002 PR-DB01
231000 PR-DB02
023100 EXEC-DB01
002310 EXEC-DB02
000231 SALES-DB01
130002 SALES-DB02
213000 SALES-DB03
021300 SALES-DB04
002130 SALES-DB05
000213 HR-DB01
300021 HR-DB02
120300 ------
012030 ------
001203 ------
300120 ------
030012 ------
203001 ------
102030 ------
010203 ------
301020 CALLCENTER-DB01
030102 CALLCENTER-DB02
203010 CALLCENTER-DB03
020301 CALLCENTER-DB04
100203 CALLCENTER-DB05
310020 CALLCENTER-DB06
031002 CALLCENTER-DB07
203100 ------
020310 SHARED-DB04
002031 ------
<#
.SYNOPSIS
Map each DB to a specific activation preference.
.DESCRIPTION
Provides a map of all existing databases on an Exchange 2010 DAG and returns if they match the activation preference.
.PARAMETER Identity
Name of a DAG to review
.EXAMPLE
Report-DAGAPDistribution.ps1 -identity DAG1
#>
[CmdLetBinding()]
param(
[parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="DAG Name to review")]
[string]$Identity
)
#http://blogs.technet.com/b/exchange/archive/2009/11/09/3408737.aspx
#This is from a 6-node DAG, I copied down the info and replaced blanks with zeros.
#DB1 Activation preference is 1,2,3
#This coverted to 123000
$DBDistro = @('123000','012300','001230','000123','300012','230001','102300',`
'010230','001023','300102','230010','023001','100230','010023',`
'301002','230100','023010','002301','100023','310002','231000',`
'023100','002310','000231','130002','213000','021300','002130',`
'000213','300021','120300','012030','001203','300120','030012',`
'203001','102030','010203','301020','030102','203010','020301',`
'100203','310020','031002','203100','020310','002031')
#Max number of copies each DB should have.
$MaxDBCopies = "3"
$DagName = $identity
#Reads list of current server names in the DAG
$serverList = (Get-DatabaseAvailabilityGroup $DagName).servers | sort name| %{$_.name}
if ($serverList -eq $null) {
Write-Host "ERROR: No servers found in DAG: $DAGNAME" -ForegroundColor red
break}
#reads Unique names of DBS on these servers
$dbs = $serverList | %{Get-MailboxDatabase -server $_} | sort name | select -Unique Name | %{$_.name}
if ($dbs -eq $null) {
Write-Host "ERROR: No databases found in DAG: $DAGNAME" -ForegroundColor red
break
}
#Build HashTable for report
$hashtable = @{}
$DBDistro | %{$hashtable[$_] = "------"}
ForEach ($db in $dbs) {
$ap = (get-mailboxdatabase $db).ActivationPreference | sort key
$APStr = ""
ForEach ($server in $serverList) {
$find = [string]($ap | ?{$_.Key -eq $server}).value
if ($find -eq "") {$find = "0"}
if ($find -gt $MaxDBCopies) {$find = "0"}
$APStr += $find
}
if ($hashtable[$apstr] -eq $null){
#This entry does not exist in the Hashtable
Write-Host "ERROR: Bad Activation Preference - $DB is $apstr " -ForegroundColor yellow
}elseif ($hashtable[$apstr] -ne "------") {
#This entry has been already used by another DB.
Write-Host "ERROR: Duplicate use of Activation Preference ($apstr)",$hashtable[$apstr],$db -ForegroundColor yellow
} else {
$hashtable[$apstr]=$db
}
}
#Output report to screen
$DBDistro | %{Write-Host $_,$hashtable[$_]}
#Output string sort of Hasttable.
#$hashtable.GetEnumerator() | Sort-Object Name
No comments:
Post a Comment