Get-ReplicationHealth.ps1

My current work project is to add an Australia-wide Lync deployment into a much larger global installation.

As part of this I’ve found it’s sometimes a challenge to monitor just those bits that I’m responsible for. The Command “get-CsManagementStoreReplicationStatus” – or “get-CsMana<tab><tab>” as I prefer to call it – outputs too much “noise”, scrolling many screens showing the health of servers on the other side of the planet, and over which I have no control (and thus, interest).

Hence, I now have a script that I can hard-code with the FEs and SBAs I’m concerned about, and it will query their replication status and give me a nice summary at the bottom of the output.
 

$SiteList = @("<FE1-FQDN>")
$SiteList += "<FE2-FQDN>"
$SiteList += "<FE3-FQDN>"
$SiteList += "<FE4-FQDN>"
$SiteList += "<FE5-FQDN>"
$SiteList += "<FE6-FQDN>"

$ReplicationStatusList = @()
$SitesNotReplicating = 0

#Capture user's normal foreground colour:
$savedColour = $host.ui.RawUI.ForegroundColor
$host.ui.RawUI.ForegroundColor = "Gray"

foreach ($site in $SiteList)
{
$ReplicationStatusList += invoke-expression "Get-CsManagementStoreReplicationStatus -replicaFQDN $site"
}

foreach ($status in $ReplicationStatusList)
{
if ($status.UpToDate -like "False")
{
$host.ui.RawUI.ForegroundColor = "Red"
write-output "UpToDate           : False"
$host.ui.RawUI.ForegroundColor = "Gray"
$SitesNotReplicating++
}
else
{
write-output "UpToDate           : True"
}
write-output "ReplicaFqdn        : $($status.ReplicaFqdn)"
write-output "LastStatusReport   : $($status.LastStatusReport)"
write-output "LastUpdateCreation : $($status.LastUpdateCreation)"
write-output "ProductVersion     : $($status.ProductVersion)"
write-output ""
}

if ($SitesNotReplicating -eq 0)
{
write-output "All sites replicating OK"
}
else
{
if ($SitesNotReplicating -eq 1)
{
write-warning "1 site is not replicating"
}
else
{
write-warning "$($SitesNotReplicating) sites are not replicating"
}
}

#Restore saved colour:
$host.ui.RawUI.ForegroundColor = $savedColour

 
If you’re actually interested in seeing the health of an ENTIRE Lync deployment, here’s the slightly more compact alternative version:

$ReplicationStatusList = @()
$SitesNotReplicating = 0

#Capture user's normal foreground colour:
$savedColour = $host.ui.RawUI.ForegroundColor
$host.ui.RawUI.ForegroundColor = "Gray"

$ReplicationStatusList += invoke-expression "Get-CsManagementStoreReplicationStatus"

foreach ($status in $ReplicationStatusList)
{
if ($status.UpToDate -like "False")
{
$host.ui.RawUI.ForegroundColor = "Red"
write-output "UpToDate           : False"
$host.ui.RawUI.ForegroundColor = "Gray"
$SitesNotReplicating++
}
else
{
write-output "UpToDate           : True"
}
write-output "ReplicaFqdn        : $($status.ReplicaFqdn)"
write-output "LastStatusReport   : $($status.LastStatusReport)"
write-output "LastUpdateCreation : $($status.LastUpdateCreation)"
write-output "ProductVersion     : $($status.ProductVersion)"
write-output ""
}

if ($SitesNotReplicating -eq 0)
{
write-output "All sites replicating OK"
}
else
{
if ($SitesNotReplicating -eq 1)
{
write-warning "1 site is not replicating"
}
else
{
write-warning "$($SitesNotReplicating) sites are not replicating"
}
}

#Restore saved colour:
$host.ui.RawUI.ForegroundColor = $savedColour

 
Feel free to tweak either version to suit your own purposes. I humm’d and haa’d over whether to suppress the display of the healthy sites, only outputting to the screen the sites that require some attention, so I’ll leave that choice to you.

Enjoy.

 

– G.
 

Colour commands reference:
http://blogs.technet.com/b/heyscriptingguy/archive/2012/10/11/powertip-write-powershell-output-in-color-without-using-write-host.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *

... and please just confirm for me that you're not a bot first: Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.