Determine the Number of Active Users on Exchange Servers with PowerShell
It’s always good to know how many users might be affected by an taking a server down. The following PowerShell function will grab performance counter data from each server to determine the number of active OWA and RPC connections:
function Get-CASActiveUsers {
[CmdletBinding()]
param(
[Parameter(Position=0,
ParameterSetName="Value", Mandatory=$true)]
[String[]]$ComputerName,
[Parameter(Position=0, ParameterSetName="Pipeline",
ValueFromPipelineByPropertyName=$true,
Mandatory=$true)]
[String]$Name
)
process {
switch($PsCmdlet.ParameterSetName)
{
"Value" {$servers =
$ComputerName}
"Pipeline" {$servers =
$Name}
}
$servers |
%{
$RPC = Get-Counter "\MSExchange
RpcClientAccess\User Count" -ComputerName $_
$OWA = Get-Counter "\MSExchange OWA\Current Unique Users" -ComputerName
$_
New-Object PSObject -Property
@{
Server =
$_
"RPC Client Access" =
$RPC.CounterSamples[0].CookedValue
"Outlook Web App" =
$OWA.CounterSamples[0].CookedValue
}
}
}
}
Just add the function to your shell session and when you run it, specify one or more server names using the -ComputerName parameter:
Get-CASActiveUsers -ComputerName ex1,ex2
The function is also written to support pipeline input, so you can pipe the Get-ClientAccessServer cmdlet to it as well:
Get-ClientAccessServer | Get-CASActiveUsers
It can take a few minutes before the values are updated as clients connect or disconnect.