ActiveUsers.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#region Functions

#region Get-OWAUsers
function Get-OWAUsers
{
    <#
        .SYNOPSIS
        Gets the number of users currectly connected to Outlook Web App.
 
        .PARAMETER ComputerName
        The computer to query.
    #>


    Param
    (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
        [Alias("Name","Server")]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )

    Begin{}

    Process
    {

        foreach($c in $ComputerName)
        {            
            $counter = Get-Counter -Counter "\MSExchange OWA\Current Unique Users" -MaxSamples 1 -ComputerName $c

            $obj = New-Object psobject
            $obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $c
            $obj | Add-Member -MemberType NoteProperty -Name OWAUsers -Value $counter.CounterSamples[0].CookedValue
            $obj
        }
    }
        
    End{}
}
#endregion

#region Get-RPCUsers
function Get-RPCUsers
{
    <#
        .SYNOPSIS
        Gets the number of rpc users currently connected.
 
        .PARAMETER ComputerName
        The computer to query.
    #>


    Param
    (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
        [Alias("Name", "Server")]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )

    Begin{}

    Process
    {

        foreach($c in $ComputerName)
        {            
            $counter = Get-Counter "\MSExchange RpcClientAccess\User Count" -MaxSamples 1 -ComputerName $c

            $obj = New-Object psobject
            $obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $c
            $obj | Add-Member -MemberType NoteProperty -Name RPCUsers -Value $counter.CounterSamples[0].CookedValue
            $obj
        }
    }
        
    End{}
}
#endregion

#region Get-ActiveSyncUsers
function Get-ActiveSyncUsers
{
    <#
        .SYNOPSIS
        Gets the number of currently connected active sync users
 
        .PARAMETER ComputerName
        The computer to query.
    #>


    Param
    (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
        [Alias("Name", "Server")]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )

    Begin{}

    Process
    {

        foreach($c in $ComputerName)
        {            
            $counter = Get-Counter "\MSExchange ActiveSync\Current Requests" -MaxSamples 1 -ComputerName $c

            $obj = New-Object psobject
            $obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $c
            $obj | Add-Member -MemberType NoteProperty -Name ActiveSyncUsers -Value $counter.CounterSamples[0].CookedValue
            $obj
        }
    }
        
    End{}
}
#endregion

#region Get-ExchangeUsers
function Get-ExchangeUsers
{
    <#
        .SYNOPSIS
        Gets the number of connected users on an Exchange server.
 
        .PARAMETER ComputerName
        The computer to query.
    #>


    Param
    (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
        [Alias("Name", "Server")]
        [string[]]$ComputerName = $env:COMPUTERNAME
    )

    Begin{}

    Process
    {

        foreach($c in $ComputerName)
        {
            $owa = Get-OWAUsers -ComputerName $c
            $rpc = Get-RPCUsers -ComputerName $c
            $activesync = Get-ActiveSyncUsers -ComputerName $c

            $obj = New-Object psobject
            $obj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $c
            $obj | Add-Member -MemberType NoteProperty -Name OWAUsers -Value $owa.owausers
            $obj | Add-Member -MemberType NoteProperty -Name RPCUsers -Value $rpc.rpcusers
            $obj | Add-Member -MemberType NoteProperty -Name ActiveSyncUsers -Value $activesync.activesyncusers
            $obj
        }
    }
        
    End{}
}
#endregion

#endregion

#region Exports
Export-ModuleMember -Function Get-OWAUsers
Export-ModuleMember -Function Get-RPCusers
Export-ModuleMember -Function Get-ActiveSyncUsers
Export-ModuleMember -Function Get-ExchangeUsers
#endregion