Exchange 2010 CAS RPC & OWA active connections

This post is also available in: Polish

Sometimes you want to know how many users connect do your Exchange 2010 Client Access Servers. This information is useful then you are using Network Load Balancer or Hardware Load Balancer.
Then you can easily check if it works perfectly.

Information about users connections to specified CAS server you can get from Counters:

  •  MSExchange RpcClientAccess\User Count
  • MSExchange OWA\Current Unique Users

 

You can get value of those counters using Exchange Management Shell and paste following powershell code:

 

$CASServers = Get-ClientAccessServer | select name

Foreach ($srv in $CASServers){
 $RPC = Get-Counter "\MSExchange RpcClientAccess\User Count" -ComputerName $srv.name
 $OWA = Get-Counter "\MSExchange OWA\Current Unique Users" -ComputerName $srv.name
 New-Object PSObject -Property @{
 Server = $srv.name
 "RPC Client Access" = $RPC.CounterSamples[0].CookedValue
 "Outlook Web App" = $OWA.CounterSamples[0].CookedValue
 }
}

 

You only need to have access to all CAS servers, then you will get result like below:

 

CAS_statistics

 

 

Print Friendly
Tagged , , . Bookmark the permalink.

12 Responses to Exchange 2010 CAS RPC & OWA active connections

  1. That’s nice. I have a basic version of this script over at:

    http://oxfordsbsguy.com/2013/06/20/powershell-identify-the-number-of-users-connected-to-a-exchange-2010-cas-server/

    I’ve been trying to figure out the best way to identify which users are connected to which CAS server, the only way I found was to check the iis logs on each server, which isn;t very dynamic. Do you know of a better way?

    Thanks,
    Carl

    • Remigiusz Szatkowski says:

      Hi
      To identify which users are connected to which CAS server you can try to use Get-LogonStatistics
      You will get information about ClientName – CAS server when you specirfy ApplicationId like Client=MSExchangeRPC or ApplicationId like Client=OWA.
      Then you need to add LogonTime and you will get what you want.

    • jason says:

      Carl,
      Your script worked a little better by specifing the actual servers. I’m guessing my 2007 cas servers were causing the issue.

  2. jason says:

    What is really odd is this script doesn’t run in our Exchange 2010 SP2 5v2 behind a HLB environment but it does run in our Exchange 2010 SP3 RU1 Test Environment, that isn’t behind a HLB.

    [PS] C:\>./rpcactiveconnections.ps1
    Get-Counter : The specified object was not found on the computer.
    At C:\rpcactiveconnections.ps1:4 char:20
    + $RPC = Get-Counter <<<< "MSExchange RpcClientAccess\User Count" -ComputerName $srv.name
    + CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

    Cannot index into a null array.
    At C:\rpcactiveconnections.ps1:7 char:44
    + "RPC Client Access" = $RPC.CounterSamples[ <<<< 0].CookedValue
    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Get-Counter : The specified object was not found on the computer.
    At C:\rpcactiveconnections.ps1:4 char:20
    + $RPC = Get-Counter <<<< "MSExchange RpcClientAccess\User Count" -ComputerName $srv.name
    + CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

    Cannot index into a null array.
    At C:\rpcactiveconnections.ps1:7 char:44
    + "RPC Client Access" = $RPC.CounterSamples[ <<<< 0].CookedValue
    + CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Server
    ——
    server1
    server2
    server3
    server4

    • Remigiusz Szatkowski says:

      Hi
      I’ve checked this script with Exchange 2010 SP2 RU5v2 and it works, but I don’t use HLB.
      In your environment with HLB can you try to run:
      Get-ClientAccessServer | select name
      Will you get all yours CAS servers ?
      next try to run:
      Get-Counter “\MSExchange RpcClientAccess\User Count” -ComputerName casservername
      Did you get any value or just error ?
      maybe you don’t have needed rights or WinRM enabled ?
      Maybe HLB is the problem, but I can’t check that.

      • jason says:

        Both those commands worked fine and I subbed the -ComputerName actualservername.
        I’m not a scripting guru so do I need to sub my actual cas server host names in the script above?

        • Remigiusz Szatkowski says:

          You should get your cas server names in variable $CASServers
          $CASServers = Get-ClientAccessServer | select name
          then run $CASServers you should get list of your cas servers.
          try to run
          Get-Counter “\MSExchange RpcClientAccess\User Count” -ComputerName casservername
          where casservername use cas server name where you are logged, do you get any value ?
          next run again Get-Counter “\MSExchange RpcClientAccess\User Count” -ComputerName casservername
          but use as casservername other cas server name where you are now not logged, will you get any value ?

          • jason says:

            I will try again tomorrow. It did however return our legacy 2007 cas servers when I ran the Get-ClientAccessServer | select name
            command. maybe the full script doesn’t like the 07 servers.

            This command worked fine when i used the casservername of the cas server i was logged into:
            Get-Counter “\MSExchange RpcClientAccess\User Count” -ComputerName casservername

            I will try tomorrow with a different cas server which I’m not logged into.

  3. GK says:

    I am trying to add ActiveSync to this one….

    $CASServers = Get-ClientAccessServer | select name

    Foreach ($srv in $CASServers){
    $RPC = Get-Counter “\MSExchange RpcClientAccess\User Count” -ComputerName $srv.name
    $OWA = Get-Counter “\MSExchange OWA\Current Unique Users” -ComputerName $srv.name
    $ASY = Get-Counter “\MSExchange ActiveSync\Current Requests” -ComputerName $srv.name
    New-Object PSObject -Property @{
    Server = $srv.name
    “RPC Client Access” = $RPC.CounterSamples[0].CookedValue
    “Outlook Web App” = $OWA.CounterSamples[0].CookedValue
    “ActiveSync” = $ASY.CounterSamples[0].CookedValue
    }
    }

    It works well except the part that it gives me activesync first and then server name.

    • Remigiusz Szatkowski says:

      try this it should work:
      Function New-Array {,$args}
      $Report = new-array

      $CASServers = Get-ClientAccessServer | select name

      Foreach ($srv in $CASServers){
      $RPC = Get-Counter “\MSExchange RpcClientAccess\User Count” -ComputerName $srv.name
      $OWA = Get-Counter “\MSExchange OWA\Current Unique Users” -ComputerName $srv.name
      $ASY = Get-Counter “\MSExchange ActiveSync\Current Requests” -ComputerName $srv.name
      $cas = New-Object System.Object
      $cas | Add-Member -type NoteProperty -name Server -value $($srv.name)
      $cas | Add-Member -type NoteProperty -name RPCClientAccess -value $($RPC.CounterSamples[0].CookedValue)
      $cas | Add-Member -type NoteProperty -name OWA -value $($OWA.CounterSamples[0].CookedValue)
      $cas | Add-Member -type NoteProperty -name ActiveSync -value $($ASY.CounterSamples[0].CookedValue)

      $Report += $cas
      }

      $Report

  4. Henrik says:

    Thanks for the script!
    How can I export the result to a csv-fil? I would like to shedule the script to run every 10 min and collect the data.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>