Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Status DAG database locations

$
0
0

This is a script I wrote to show the status of all Exchange 2010 DAG databases. It displays to the EMS console color coded to see db's running off of Activation Preference location. And it will handle any size DAG.

#
# .\Status-DAG-DB-Locations.ps1
#
# Function:
#
# Status and display the current database preference of the Active mailbox database of the Database Availablity Group specified.
#
# Sample:
#
#   .\Status-DAG-DB-Locations.ps1 <DAGName>
#   i.e.: .\Status-DAG-DB-Locations.ps1 <default = DAG that this server is a member of>
#
# The script will parse through the databases on the Database Availablity Group displaying the "active" location and Activation Preference.
#
# Assumptions:
#
# Displays the current Active Database and the Activation Preference sequence number based on the mailbox database activation Preference settings.
#
#
param ([string] $DAGName)
#$DebugPreference = 'SilentlyContinue'
$DebugPreference = 'Continue'

if ($DAGName -Like $Null) {
   $computername = $env:computername
   $DAGName = Get-DatabaseAvailabilityGroup | Where {$_.Servers -Like "*$computername*"}
}
if ($DAGName -Like $Null) {
   Write-Host "Failed to specify any Database Availability Group name." -ForegroundColor Red
   Exit
}
$AllDAGNames = Get-DatabaseAvailabilityGroup
$ValidDAGName = $False
foreach ($DAG in $AllDAGNames) {
   $ValidDAG = $DAG.Name
   if ($DAGName -eq $ValidDAG) {$ValidDAGName = $True}
}
if ($ValidDAGName -eq $False) {
   Write-Host "Failed to specify a valid Database Availability Group name." -ForegroundColor Red
   Exit
}
Write-Host "DAG Name = $DAGName" -foregroundcolor green
$DBGroup = Get-MailboxDatabase | Where {$_.MasterServerOrAvailabilityGroup -Like "$DAGName" -And $_.Name -NotLike "Mailbox Database*"} | Sort Name
Write-Host "Database       Active Server   DB Prf    Activation Sequence" -ForegroundColor Green
ForEach ($DB in $DBGroup) {
   [string] $DatabaseFullName = $DB.Name
   $CopyStat = Get-MailboxDatabaseCopyStatus $DatabaseFullName
   foreach ($DBCopy in $CopyStat) {
      $CopyServer = $DBCopy.Server
      $CopyName = $DBCopy.name
      $CopyStatus = $DBCopy.Status
      $CopyServerName = $DBCopy.MailboxServer
      [double] $CopyReplayQueueLength = $DBCopy.ReplayQueueLength
      $CopyContentIndexState = $DBCopy.ContentIndexState
      $CopyCopyQueueLength = $DBCopy.CopyQueueLength
      [double] $CopyGenerated = $DBCopy.LastLogGenerated
      [double] $CopyNotified  = $DBCopy.LastLogCopyNotified
      [double] $CopyCopied    = $DBCopy.LastLogCopied
      [double] $CopyInspected = $DBCopy.LastLogInspected
      [double] $CopyReplayed  = $DBCopy.LastLogReplayed
      # Series of checks for any queues to give immediate alert (You can increase the threshold to keep the chatter down.)
      $CopyMounted   = $DBCopy.ActiveCopy
      $CopyComputed = $CopyGenerated - $CopyReplayed - $CopyReplayQueueLength
      if ($CopyComputed -ne 0) {
          write-host "Issue on database $CopyName on server $CopyServerName with the LastLogGenerated Count." -ForegroundColor Red
          write-host "LastLogGenerated = $CopyGenerated - LastLogReplayed = $CopyReplayed - ReplayQueueLength = $CopyReplayQueueLength should equal 0 vs. $CopyComputed" -ForegroundColor Red
      }
      $CopyComputed = $CopyNotified - $CopyReplayed - $CopyReplayQueueLength
      if ($CopyComputed -ne 0) {
          write-host "Issue on database $CopyName on server $CopyServerName with the LastLogCopyNotified Count." -ForegroundColor Red
          write-host "LastLogCopyNotified = $CopyNotified - LastLogReplayed = $CopyReplayed - ReplayQueueLength = $CopyReplayQueueLength should equal 0 vs. $CopyComputed" -ForegroundColor Red
      }
      $CopyComputed = $CopyCopied - $CopyReplayed - $CopyReplayQueueLength
      if ($CopyComputed -ne 0) {
          write-host "Issue on database $CopyName on server $CopyServerName with the LastLogCopied Count." -ForegroundColor Red
          write-host "LastLogCopied = $CopyCopied - LastLogReplayed = $CopyReplayed - ReplayQueueLength = $CopyReplayQueueLength should equal 0 vs. $CopyComputed" -ForegroundColor Red
      }
      $CopyComputed = $CopyInspected - $CopyReplayed - $CopyReplayQueueLength
      if ($CopyComputed -ne 0) {
          write-host "Issue on database $CopyName on server $CopyServerName with the LastLogInspected Count." -ForegroundColor Red
          write-host "LastLogInspected = $CopyInspected - LastLogReplayed = $CopyReplayed - ReplayQueueLength = $CopyReplayQueueLength should equal 0 vs. $CopyComputed" -ForegroundColor Red
      }
      # Check CopyQueueLength and CopyContentIndexState     
      if ($CopyCopyQueueLength -gt 0) {
         write-host "Database Copy Queue Length: $CopyCopyQueueLength found on $CopyName" -ForegroundColor Red
      }
      if ($CopyStatus -eq "Healthy" -Or $CopyStatus -eq "Mounted") {
         # Take no action on healthy databases
         # Only display if Status not Health or Mounted
      } Else {
         # Rather than taking action on suspended or unhealthy databases the object of this script is to report
         if ($CopyStatus -like "Suspended") {
            Write-Host "Database Copy: $CopyName found $CopyStatus" -ForegroundColor Red
         } Else {
            Write-Host "Database Copy: $CopyName found with Status: $CopyStatus" -ForegroundColor Red
         }
      }
      if ($CopyContentIndexState -NE "Healthy") {
         write-host "Database Copy: $CopyName on server $CopyServerName found ContentIndexState: $CopyContentIndexState" -ForegroundColor Red
      }
   }
   [string] $DatabaseName = $DB.Name
   [string] $DBPrefString = $DB.ActivationPreference
   $DBPrefString = $DBPrefString.Replace("[","")
   $DBPrefString = $DBPrefString.Replace("]","")
   [string] $DBPref = $DB.ActivationPreference
   $ActiveServerName = $DB.ServerName
   $DBNampart = $DatabaseName.split("-")
   $DatabaseName = $DBNampart[2]
   $DBPref = $DBPref.substring(0,(($DBPref.length) -1))
   $DBPref = $DBPref.replace(",","%")
   $DBPref = $DBPref.replace("[","")
   $DBPref = $DBPref.replace(" ","")
   $DBPref = $DBPref.replace("]",",")
   $DBPrefSeq = $DBPref.split(",")
   $Count = $DBPrefSeq.count
   $i = 0
   $CurrentActivationPreference = $null
   $DBPreference = @()
   $DBActivation = @()
   do {
      $x = $DBPrefSeq[$i]
      $x = $x.split("%")
      $Server = $x[0]   
      $Activation = $x[1]   
      if ($ActiveServerName -eq $Server)
      {
         $CurrentActivationPreference = $Activation
      }
      $DBPreference += $Server 
      $DBActivation += $Activation 
      #Write-Host "DBPreference $Server"
      $i++
   } until ($i -eq $Count)
   $i = 0
   $PreferredServerName = $DBPreference[0]
   $DispColor = "Green"
   $BackGR = "Black"
   if ($CurrentActivationPreference -eq "1") {$DispColor = "Green"}
   if ($CurrentActivationPreference -eq "2") {$DispColor = "DarkGreen"; $BackGR = "White"}
   if ($CurrentActivationPreference -eq "3") {$DispColor = "Yellow"}
   if ($CurrentActivationPreference -eq "4") {$DispColor = "Yellow"; $BackGR = "Blue"}
   if ($CurrentActivationPreference -eq "5") {$DispColor = "Red"; $BackGR = "White"}
   if ($CurrentActivationPreference -eq "6") {$DispColor = "DarkRed"; $BackGR = "White"}
   if ($CurrentActivationPreference -eq "7") {$DispColor = "Cyan"}
   if ($CurrentActivationPreference -eq "8") {$DispColor = "DarkCyan"}
   if ($CurrentActivationPreference -eq "9") {$DispColor = "Magenta"}
   if ($CurrentActivationPreference -eq "10") {$DispColor = "DarkMagenta"}
   if ($CurrentActivationPreference -eq "11") {$DispColor = "Gray"}
   if ($CurrentActivationPreference -eq "12") {$DispColor = "DarkGray"}
   if ($CurrentActivationPreference -eq "13") {$DispColor = "Blue"}
   if ($CurrentActivationPreference -eq "14") {$DispColor = "DarkBlue"}
   if ($CurrentActivationPreference -eq "15") {$DispColor = "White"}
   if ($CurrentActivationPreference -eq "16") {$DispColor = "White"; $BackGR = "Yellow"}
   Write-Host "$DatabaseFullName `t $ActiveServerName `t $CurrentActivationPreference `t $DBPrefString" -ForegroundColor $DispColor -BackgroundColor $BackGR
}

 


Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images