-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-userstreams.ps1
228 lines (191 loc) · 8.17 KB
/
get-userstreams.ps1
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<#
.SYNOPSIS
Main script to pull back data using Get-CsUserSession into CSV. The main purpose of the data output will be used in Power BI reporting.
.DESCRIPTION
This scripts calls upon multiple modules to handle credential management, processing of users in batches, managing the pssession to prevent time-out and utilizing
multiple functions to pull data out of the Get-CsUserSesion to be populated in csv.
.NOTES
This script is currently under development along with the accomplining Power BI Reports.
Any questions / feedback please reach out to gclark01
.EXAMPLE
get-userstreams.ps1 -Type Report -startTime 04/01/2018 -endTime 04/15/2018 -ReportPath c:\temp\reports
#>
# Enabling Advanced Functions
#[cmdletbinding()]
Param(
[parameter (Mandatory = $true)]
[ValidateSet("Report")]
[string]$Type,
[parameter(Mandatory = $true)]
[datetime]$startTime,
[parameter(Mandatory = $true)]
[datetime]$endTime,
[string]$CsvUsers,
[parameter(Mandatory = $true)]
[string]$ReportPath
)
# Global Variables
$endTime = $endTime.AddDays(1)
$Date = (Get-Date).ToString("MMddyyyy_hhmmss")
$ReportPath = $ReportPath + "\" + "Reports" + "-" + $Date
$Global:AudioFileName = "audio-records.csv"
$Global:AudioReports = $ReportPath + "\" + $Global:AudioFileName
$Global:ReliabilityFileName = "reliability-records.csv"
$Global:ReliabilityReports = $ReportPath + "\" + $Global:ReliabilityFileName
$Global:VbssFileName = "vbss-records.csv"
$Global:VbssReports = $ReportPath + "\" + $Global:VbssFileName
$Global:VideoFileName = "video-records.csv"
$Global:VideoReports = $ReportPath + "\" + $Global:VideoFileName
$Global:AppShareFileName = "appshare-records.csv"
$Global:AppShareReports = $ReportPath + "\" + $Global:AppShareFileName
$Global:RMCFileName = "rmc-records.csv"
$Global:RMCReports = $ReportPath + "\" + $Global:RMCFileName
$Global:IMFEDFileName = "imfed-records.csv"
$Global:IMFEDReports = $ReportPath + "\" + $Global:IMFEDFileName
$Global:UserRegFileName = "lastreg-records.csv"
$Global:UserRegReports = $Reportpath + "\" + $Global:UserRegFileName
$Global:LogPath = $env:TEMP + "\" + "Logs" + "\" + $Date
# Set path to save logs
if (! ([IO.Directory]::Exists($LogPath))) {
try {
New-Item -Path $LogPath -ItemType Directory | Out-Null
}
catch {
throw;
}
}
# Set path to save reports
if (! ([IO.Directory]::Exists($ReportPath))) {
try {
New-Item -Path $ReportPath -ItemType Directory | Out-Null
}
catch {
throw;
}
}
#Create new File (Report)
New-Item -Path $ReportPath -Name $Global:AudioFileName -ItemType File | Out-Null
New-Item -Path $ReportPath -Name $Global:ReliabilityFileName -ItemType File | Out-Null
New-Item -Path $ReportPath -Name $Global:VbssFileName -ItemType File | Out-Null
New-Item -Path $ReportPath -Name $Global:VideoFileName -ItemType File | Out-Null
New-Item -Path $ReportPath -Name $Global:AppShareFileName -ItemType File | Out-Null
New-Item -Path $ReportPath -Name $Global:RMCFileName -ItemType File | Out-Null
New-Item -Path $ReportPath -Name $Global:IMFEDFileName -ItemType File | Out-Null
New-Item -Path $ReportPath -Name $Global:UserRegFileName -ItemType File | Out-Null
<#
# Remove script module if previously loaded
if (Get-Module -Name PSSessions) {
Remove-Module -Name PSSessions
}
if (Get-Module -Name CredentialManager) {
Remove-Module -Name CredentialManager
}
if (Get-Module -Name BatchUsers) {
Remove-Module -Name BatchUsers
}
if (Get-Module -Name SessionData) {
Remove-Module -Name SessionData
}
#>
# Import Modules
Get-ChildItem -Path $PSScriptRoot\Modules\*.ps*1 | ForEach-Object {Import-Module $_.pspath -Force }
<#
# Load script Modules
# Import-Module LyncOnlineConnector
Import-Module .\Modules\CredentialManager.psd1
Import-Module .\Modules\PSSessions.psm1
Import-Module .\Modules\BatchUsers.psm1
Import-Module .\Modules\SessionData.psm1
#>
# This starts the inital logon process and loads the remote ps session
$scriptStart = Get-Date
Get-MySession
# Get all users
if ($CsvUsers) {
$OnlineUsers = Import-Csv $CsvUsers
}
else {
$OnlineUsers = Get-CsOnlineUser -Filter {(Enabled -eq $True) -and (SipAddress -like "sip*")} -WarningAction SilentlyContinue | Select-Object UserPrincipalName, SipAddress | Sort-Object -Property SipAddress
}
# Process users into batches
$Batch = Get-BatchUsers -Users $OnlineUsers
# For Testing Purpoose
Write-Host "Count of users found $($OnlineUsers.Count)" -BackgroundColor Red
#Process batch of users
foreach ($userKey in $Batch.Values) {
# Write how many Batches have been created
Write-Host "Created $($Batch.Count) unique user batches to be processed. Max batch size is 500 users" -ForegroundColor Yellow
# Define variables used during processing of user batches
$batchCount ++
$pStartTime = Get-Date
# Write what batch is currently being processed
Write-Host "Processing $($batchCount) batch of users out of $($Batch.Count) batches created" -ForegroundColor Yellow
if ($batchCount -gt 1) {
# Determine how much time is left in comparison to how long the last batch took to run
$Global:TimeRemaining = New-TimeSpan -Start $Global:SessionTime -End $pEndTime
# Validate how much time is left, before continuing
if ($Global:TimetoComplete.TotalSeconds -gt $Global:TimeRemaining.TotalSeconds ) {
# If the batch took longer than expected, we should update the session before moving forward
Get-MySession -ForceUpdate
}
else {
# Check to see if we are over the session timer limit of 45 minutes
Get-MySession
}
}
foreach ($userObject in $userKey) {
switch ($Type) {
AudioEvents {
$AudioEvents = Get-AudioEvents -userHash $userObject -startTime $startTime -endTime $endTime
# Write results to CSV
if ($AudioEvents) {
$AudioEvents | Export-Csv -Path "c:\temp\audioevents.csv" -NoTypeInformation -Append
}
}
AudioQuality {
$AudioQuality = Get-AudioQuality -userHash $userObject -startTime $startTime -endTime $endTime
# Write results to CSV
if ($AudioQuality) {
$AudioQuality | Export-Csv -Path "c:\temp\audioquality.csv" -NoTypeInformation -Append
}
}
VideoApplicationSharing {
$VideoAppSharing = Get-VideoAppSharingStreams -userHash $userObject -startTime $startTime -endTime $endTime
# Write results to CSV
if ($VideoAppSharing) {
$VideoAppSharing | Export-Csv -Path "c:\temp\vbssquality.csv" -NoTypeInformation -Append
}
}
IMFED {
$IMFED = Get-IMFederatedDomains -userHash $userObject -startTime $startTime -endTime $endTime
if ($IMFED) {
$IMFED | Export-Csv -Path "c:\temp\imfeddomains.csv" -NoTypeInformation -Append
}
}
SetupOrDrop {
$SoD = Get-SetupOrDrops -userHash $userObject -startTime $startTime -endTime $endTime
if ($SoD) {
$SoD | Export-Csv -Path "c:\temp\reliability.csv" -NoTypeInformation -Append
}
}
RMC {
$RMC = Get-RMC -userHash $userObject -startTime $startTime -endTime $endTime
if ($RMC) {
$RMC | Export-Csv -Path "c:\temp\ratemycall.csv" -NoTypeInformation -Append
}
}
Report {
Get-QoEReport -userHash $userObject -startTime $startTime -endTime $endTime
}
Default {
Write-Error -Message "You must select a report type to run!"
}
}
}
# Define variables used to determine length of time spent processing the user batches.
$pEndTime = Get-Date
$Global:TimetoComplete = New-TimeSpan -Start $pStartTime -End $pEndTime
}
$endScript = Get-Date
$ScriptTimetoComplete = New-TimeSpan -Start $scriptStart -End $endScript
Write-Host "Total Time to complete Script: $($ScriptTimetoComplete)" -ForegroundColor Yellow