Skip to content

A Simple Powershell Script to Show RPC Connections to Exchange CAS Servers

I ran into to this when I was trying to shut down a CAS box to apply patches. We have two CAS servers in a Windows Load balanced Array, so the least disruptive way to kick everyone off a node so you can reboot it is to order a Drainstop on one node. This keeps current connections active, but doesn’t allow new connections. After a few hours, especially at the end of the day, your connections will drop off to acceptable levels for a reboot.

I wanted a Powershell method to check on the status of a Drainstop command, and I discovered the hooks Powershell has into Windows’ Performance Monitor. Here’s the script (you can run it remotely with the right permissions):

$cas = {Server1}, {Server2}
$active = $cas | %{Get-Counter -computername $_ -Counter "\MSExchange RPCClientAccess\Active User Count" | select -expandproperty CounterSamples | select CookedValue }
$connection = $cas | %{Get-Counter -computername $_ -Counter "\MSExchange RPCClientAccess\Connection Count" | select -expandproperty CounterSamples | select CookedValue }
Write-host Server1
Write-host Connections............. $connection[0].CookedValue
Write-host Active Users............ $active[0].CookedValue
Write-host Server
Write-host Connections............. $connection[1].CookedValue
Write-host Active Users............ $active[1].CookedValue

It may not be the most elegant script I’ve ever written, but it gets the job done faster than loading up perfmon every time I want to glance at this.

The CookedValue expanded property is new to me, and it makes parsing actual values out of this much simpler. Otherwise, it will just return an object that isn’t easy to stick in a readable write-host statement.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*