Posted in
Windows Powershell |
1 Comment | 17,607 views | 22/05/2013 15:30
In this sample, I’ll show you how to get active Exchange Server CAS connections via PowerShell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| $ExchangeHost = "ExCas01"
$ExchangeServer = Get-ExchangeServer -Identity $ExchangeHost
# Get Connections
if ($ExchangeServer.IsClientAccessServer -eq $True)
{
# OWA Connections
$HostOWAConnections = (Get-Counter "\MSExchange OWA\Current Unique Users" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# RPC Connections
$HostRPCConnections = (Get-Counter "\MSExchange RpcClientAccess\User Count" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# POP3 Connections
$HostPOP3Connections = (Get-Counter "\MSExchangePop3(1)\Connections Current" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# IMAP Connections
$HostIMAPConnections = (Get-Counter "\MSExchangeImap4(1)\Current Connections" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# Exchange Connections
[int]$ExchangeActiveConnections = [int]$HostOWAConnections + [int]$HostRPCConnections + [int]$HostPOP3Connections + [int]$HostIMAPConnections
} |
$ExchangeHost = "ExCas01"
$ExchangeServer = Get-ExchangeServer -Identity $ExchangeHost
# Get Connections
if ($ExchangeServer.IsClientAccessServer -eq $True)
{
# OWA Connections
$HostOWAConnections = (Get-Counter "\MSExchange OWA\Current Unique Users" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# RPC Connections
$HostRPCConnections = (Get-Counter "\MSExchange RpcClientAccess\User Count" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# POP3 Connections
$HostPOP3Connections = (Get-Counter "\MSExchangePop3(1)\Connections Current" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# IMAP Connections
$HostIMAPConnections = (Get-Counter "\MSExchangeImap4(1)\Current Connections" -ComputerName $ExchangeHost).CounterSamples[0].CookedValue
# Exchange Connections
[int]$ExchangeActiveConnections = [int]$HostOWAConnections + [int]$HostRPCConnections + [int]$HostPOP3Connections + [int]$HostIMAPConnections
}
You can loop this script to get real time connection statistics.