-
Notifications
You must be signed in to change notification settings - Fork 11
/
ExchangeLogCollector.ps1
2234 lines (1993 loc) · 92.5 KB
/
ExchangeLogCollector.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.NOTES
Name: ExchangeLogCollector.ps1
Author: David Paulson
Requires: Powershell on an Exchange 2010+ Server with Adminstrator rights
Version History:
2.0.0 - Major updates have been made to the script and a new publish of it was done.
2.0.1 - Missing HTTPErr Logs to the script.
2.0.2 - Fix Bug with loading EMS and search directory
2.0.3 - Switch "ClusterLogs" to "High_Availabilty_Logs" and adjust the switch as well to avoid confusion.
Added a feature that checks to see if you pass some switches or it throws a warning asking are you sure to continue.
2.1 - Major Updates. Remote Collection now possible with -Server switch. Moved over to github.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
.SYNOPSIS
Collects the requested logs off the Exchange server based off the switches that are used.
.DESCRIPTION
Collects the requested logs off the Exchange server based off the switches that are used.
.PARAMETER FilePath
The Location of where you would like the data to be copied over to
.PARAMETER Servers
An array of servers that you would like to collect data from.
.PARAMETER EWSLogs
Will collect the EWS logs from the Exchange Server
.PARAMETER IISLogs
Will Collect the IIS Logs from the Exchange Server
.PARAMETER DailyPerformanceLogs
Used to collect Exchange 2013+ Daily Performance Logs
.PARAMETER ManagedAvailability
Used to collect managed Availability Logs from the Exchange 2013+ Server
.PARAMETER Experfwiz
Used to collect Experfwiz data from the server
.PARAMETER RPCLogs
Used to collect the PRC Logs from the server
.PARAMETER EASLogs
Used to collect the Exchange Active Sync Proxy Logs
.PARAMETER ECPLogs
Used to collect the ECP Logs from the Exchange server
.PARAMETER AutoDLogs
Used to Collect the AutoD Logs from the server
.PARAMETER OWALogs
Used to collect the OWA Logs from the server
.PARAMETER ADDriverLogs
Used to collect the AD Driver Logs from the server
.PARAMETER SearchLogs
Used to collect the Search Logs from the server
.PARAMETER HighAvailabilityLogs
Used to collect the High Availability Information from the server
.PARAMETER MapiLogs
Used to collect the Mapi Logs from the server
.PARAMETER MessageTrackingLogs
Used to collect the Message Tracking Logs from the server
.PARAMETER HubProtocolLogs
Used to collect the Hub Protocol Logs from the server
.PARAMETER HubConnectivityLogs
Used to collect the Hub Connectivity Logs from the server
.PARAMETER FrontEndConnectivityLogs
Used to collect the Front End Connectivity Logs from the server
.PARAMETER FrontEndProtocolLogs
Used to collect the Front End Protocol Logs from the server
.PARAMETER MailboxConnectivityLogs
Used to collect the Mailbox Connectivity Logs from the server
.PARAMETER MailboxProtocolLogs
Used to collect the Mailbox Protocol Logs from the server
.PARAMETER QueueInformationThisServer
Used to collect the Queue Information from this server
.PARAMETER ReceiveConnectors
Used to collect the Receive Connector information from this server
.PARAMETER SendConnectors
Used to collect the Send connector information from the Org
.PARAMETER DAGInformation
Used to collect the DAG Information for this DAG
.PARAMETER GetVdirs
Used to collect the Virtual Directories of the environment
.PARAMETER TransportConfig
Used to collect the Transport Configuration from this Exchange Server
.PARAMETER DefaultTransportLogging
Used to Get all the default logging that is enabled on the Exchange Server for Transport Information
.PARAMETER Exmon
Used to Collect the Exmon Information
.PARAMETER ServerInfo
Used to collect the general Server information from the server
.PARAMETER MSInfo
Old switch that was used for collecting the general Server information
.PARAMETER CollectAllLogsBasedOnDaysWorth
Used to collect some of the default logging based off Days Worth vs the whole directory
.PARAMETER DiskCheckOverride
Used to over the Availalbe Disk space required in order this script to run
.PARAMETER AppSysLogs
Used to collect the Application and System Logs. Default is set to true
.PARAMETER AllPossibleLogs
Switch to enable all default logging enabled on the Exchange server.
.PARAMETER NoZip
Used to not zip up the data by default
.PARAMETER SkipEndCopyOver
Boolean to prevent the copy over after a remote collection.
#PARAMETER CustomData - Might bring this back in later build.
Used to collect data from a custom directory
#PARAMETER CustomDataDirectory
Tell which directory you would like to collect data from
.PARAMETER DaysWorth
To determine how far back we would like to collect data from
.PARAMETER ScriptDebug
To enable Debug Logging for the script to determine what might be wrong with the script
.PARAMETER DatabaseFailoverIssue
To enable the common switches to assist with determine the cause of database failover issues
.PARAMETER Experfwiz_LogmanName
To be able to set the Experfwiz Logman Name that we would be looking for. By Default "Exchange_Perfwiz"
.PARAMETER Exmon_LogmanName
To be able to set the Exmon Logman Name that we would be looking for. By Default "Exmon_Trace"
.PARAMETER AcceptEULA
Switch used to bypass the disclaimer confirmation
#>
#Parameters
[CmdletBinding()]
Param (
[string]$FilePath = "C:\MS_Logs_Collection",
[Array]$Servers,
[switch]$EWSLogs,
[switch]$IISLogs,
[switch]$DailyPerformanceLogs,
[switch]$ManagedAvailability,
[switch]$Experfwiz,
[switch]$RPCLogs,
[switch]$EASLogs,
[switch]$ECPLogs,
[switch]$AutoDLogs,
[switch]$OWALogs,
[switch]$ADDriverLogs,
[switch]$SearchLogs,
[switch]$HighAvailabilityLogs,
[switch]$ClusterLogs,
[switch]$MapiLogs,
[switch]$MessageTrackingLogs,
[switch]$HubProtocolLogs,
[switch]$HubConnectivityLogs,
[switch]$FrontEndConnectivityLogs,
[switch]$FrontEndProtocolLogs,
[switch]$MailboxConnectivityLogs,
[switch]$MailboxProtocolLogs,
[switch]$QueueInformationThisServer,
[switch]$ReceiveConnectors,
[switch]$SendConnectors,
[switch]$DAGInformation,
[switch]$GetVdirs,
[switch]$TransportConfig,
[switch]$DefaultTransportLogging,
[switch]$Exmon,
[switch]$ServerInfo,
[switch]$CollectAllLogsBasedOnDaysWorth = $false,
[switch]$DiskCheckOverride,
[switch]$AppSysLogs = $true,
[switch]$AllPossibleLogs,
[switch]$NoZip,
[bool]$SkipEndCopyOver,
[int]$DaysWorth = 3,
[switch]$DatabaseFailoverIssue,
[string]$Experfwiz_LogmanName = "Exchange_Perfwiz",
[string]$Exmon_LogmanName = "Exmon_Trace",
[switch]$AcceptEULA,
[switch]$ScriptDebug
)
$scriptVersion = 2.3
###############################################
# #
# Local Functions #
# #
###############################################
#disclaimer
Function Display-Disclaimer {
$display = @"
Exchange Log Collector v{0}
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-This script will copy over data based off the switches provied.
-We will check for at least 15 GB of free space at the local target directory BEFORE
attempting to copy over the data.
-Please run this script at your own risk.
"@ -f $scriptVersion
Clear-Host
Write-Host $display
do{
if(-not $AcceptEULA)
{
$r = Read-Host ("Do you wish to continue ('y' or 'n')")
}
else{
$r = "y"
}
}while(($r -ne "y" -and $r -ne "n"))
if(-not ($AcceptEULA) -and $r -eq "n")
{
exit
}
}
Function Display-FeedBack {
Write-Host ""
Write-Host ""
Write-Host ""
Write-Host "Looks like the script is done. If you ran into any issues or have additional feedback, please feel free to reach out [email protected]."
}
#Function to load the EXShell
Function Load-ExShell {
if($exinstall -eq $null){
$testV14 = Test-Path 'HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup'
$testV15 = Test-Path 'HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup'
if($testV14){
$Script:exinstall = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup).MsiInstallPath
}
elseif ($testV15) {
$Script:exinstall = (get-itemproperty HKLM:\SOFTWARE\Microsoft\ExchangeServer\v15\Setup).MsiInstallPath
}
else{
Write-Host "It appears that you are not on an Exchange 2010 or newer server. Sorry I am going to quit."
exit
}
$script:exbin = $Script:exinstall + "\Bin"
Write-Host "Loading Exchange PowerShell Module..."
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
}
}
#Function to test if you are an admin on the server
Function Is-Admin {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() )
If( $currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )) {
return $true
}
else {
return $false
}
}
Function Display-ScriptDebug{
param(
[Parameter(Mandatory=$true)]$stringdata
)
if($ScriptDebug)
{
Write-Host("[Script Debug] : {0}" -f $stringdata) -ForegroundColor Cyan
}
}
Function Get-ZipEnabled {
if($NoZip){return $false}
else{return $true}
}
Function Get-TransportLoggingInformationPerServer {
param(
[string]$Server,
[int]$version
)
Display-ScriptDebug("Function Enter: Get-TransportLoggingInformationPerServer")
Display-ScriptDebug("Passed - Server: {0} Version: {1}" -f $Server, $version)
$hubObject = New-Object PSCustomObject
$tranportLoggingObject = New-Object PSCustomObject
if($version -ge 15)
{
#Hub Transport Layer
$data = Get-TransportService -Identity $Server
$hubObject | Add-Member -MemberType NoteProperty -Name ConnectivityLogPath -Value ($data.ConnectivityLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name MessageTrackingLogPath -Value ($data.MessageTrackingLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name PipelineTracingPath -Value ($data.PipelineTracingPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name ReceiveProtocolLogPath -Value ($data.ReceiveProtocolLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name SendProtocolLogPath -Value ($data.SendProtocolLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name QueueLogPath -Value ($data.QueueLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name WlmLogPath -Value ($data.WlmLogPath.PathName)
$tranportLoggingObject | Add-Member -MemberType NoteProperty -Name HubLoggingInfo -Value $hubObject
#Front End Transport Layer
$FETransObject = New-Object PSCustomObject
$data = Get-FrontendTransportService -Identity $Server
$FETransObject | Add-Member -MemberType NoteProperty -Name ConnectivityLogPath -Value ($data.ConnectivityLogPath.PathName)
$FETransObject | Add-Member -MemberType NoteProperty -Name ReceiveProtocolLogPath -Value ($data.ReceiveProtocolLogPath.PathName)
$FETransObject | Add-Member -MemberType NoteProperty -Name SendProtocolLogPath -Value ($data.SendProtocolLogPath.PathName)
$FETransObject | Add-Member -MemberType NoteProperty -Name AgentLogPath -Value ($data.AgentLogPath.PathName)
$tranportLoggingObject | Add-Member -MemberType NoteProperty -Name FELoggingInfo -Value $FETransObject
#Mailbox Transport Layer
$mbxObject = New-Object PSCustomObject
$data = Get-MailboxTransportService -Identity $Server
$mbxObject | Add-Member -MemberType NoteProperty -Name ConnectivityLogPath -Value ($data.ConnectivityLogPath.PathName)
$mbxObject | Add-Member -MemberType NoteProperty -Name ReceiveProtocolLogPath -Value ($data.ReceiveProtocolLogPath.PathName)
$mbxObject | Add-Member -MemberType NoteProperty -Name SendProtocolLogPath -Value ($data.SendProtocolLogPath.PathName)
$mbxObject | Add-Member -MemberType NoteProperty -Name PipelineTracingPath -Value ($data.PipelineTracingPath.PathName)
$mbxObject | Add-Member -MemberType NoteProperty -Name MailboxDeliveryThrottlingLogPath -Value ($data.MailboxDeliveryThrottlingLogPath.PathName)
$tranportLoggingObject | Add-Member -MemberType NoteProperty -Name MBXLoggingInfo -Value $mbxObject
}
elseif($version -eq 14)
{
$data = Get-TransportServer -Identity $Server
$hubObject | Add-Member -MemberType NoteProperty -Name ConnectivityLogPath -Value ($data.ConnectivityLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name MessageTrackingLogPath -Value ($data.MessageTrackingLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name PipelineTracingPath -Value ($data.PipelineTracingPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name ReceiveProtocolLogPath -Value ($data.ReceiveProtocolLogPath.PathName)
$hubObject | Add-Member -MemberType NoteProperty -Name SendProtocolLogPath -Value ($data.SendProtocolLogPath.PathName)
$tranportLoggingObject | Add-Member -MemberType NoteProperty -Name HubLoggingInfo -Value $hubObject
}
else
{
Write-Host("trying to determine transport information for server {0} and was able to determine the correct version type" -f $Server)
return
}
Display-ScriptDebug("ReceiveConnectors: {0} QueueInformationThisServer: {1}" -f $ReceiveConnectors, $QueueInformationThisServer)
if($ReceiveConnectors)
{
$value = Get-ReceiveConnector -Server $Server
$tranportLoggingObject | Add-Member -MemberType NoteProperty -Name ReceiveConnectorData -Value $value
}
if($QueueInformationThisServer)
{
$value = Get-Queue -Server $Server
$tranportLoggingObject | Add-Member -MemberType NoteProperty -Name QueueData -Value $value
}
Display-ScriptDebug("Function Exit: Get-TransportLoggingInformationPerServer")
return $tranportLoggingObject
}
Function Get-ServerObjects {
param(
[Parameter(Mandatory=$true)][Array]$ValidServers
)
Display-ScriptDebug ("Function Enter: Get-ServerObjects")
Display-ScriptDebug ("Passed {0} of Servers" -f $ValidServers.Count)
$svrsObject = @()
$oldErrorAction = $ErrorActionPreference
$ErrorActionPreference = "Stop"
foreach($svr in $ValidServers)
{
Display-ScriptDebug -stringdata ("Working on Server {0}" -f $svr)
try{
$exchSvr = Get-ExchangeServer $svr
}
catch
{
Write-Host("Failed to detect server {0} as an Exchange Server" -f $svr) -ForegroundColor Red
Write-Host("Removing from the list")
continue
}
$sobj = New-Object PSCustomObject
$sobj | Add-Member -Name ServerName -MemberType NoteProperty -Value ($svr)
$svrRole = $exchSvr.ServerRole
Display-ScriptDebug ("Pulled out ServerRole: {0}" -f $svrRole.ToString())
#Set Exchange Version value 14 Exchange 2010, 15 Exchange 2013, 16 Exchange 2016
$svrAdmin = $exchSvr.AdminDisplayVersion
Display-ScriptDebug ("Pulled out AdminDisplayVersion: {0}" -f $svrAdmin.ToString())
if($svrAdmin.Major -eq 14)
{
$exVersion = 14
}
elseif($svrAdmin.Major -eq 15)
{
if($svrAdmin.Minor -eq 0)
{
$exVersion = 15
}
else
{
$exVersion = 16
}
}
else
{
#don't know what version of Exchange this is, we shouldn't add it
Write-Host("Unable to determine the version of Server {0} so we aren't going to collect data from it" -f $svr)
continue
}
Function IsMailbox{
param([string]$value)
if($value -like "*Mailbox*"){return $true} else{ return $false}
}
Function IsCAS{
param([string]$value,[int]$version)
if(($version -eq 16) -or ($value -like "*ClientAccess*")){return $true} else{return $false}
}
Function IsHub {
param([string]$value,[int]$version)
if(($version -ge 15) -or ($value -like "*HubTransport*")){return $true}{return $false}
}
Function IsDAGMember{
param([bool]$IsMailbox,[string]$ServerName)
if($IsMailbox)
{
if((Get-MailboxServer $ServerName).DatabaseAvailabilityGroup -ne $null){return $true}
else{return $false}
}
else {
return $false
}
}
$sobj | Add-Member -Name Mailbox -MemberType NoteProperty -Value (IsMailbox -Value $svrRole)
$sobj | Add-Member -Name CAS -MemberType NoteProperty -Value (IsCAS -Value $svrRole -Version $exVersion)
$sobj | Add-Member -Name Hub -MemberType NoteProperty -Value (IsHub -Value $svrRole -Version $exVersion)
$sobj | Add-Member -Name Version -MemberType NoteProperty -Value $exVersion
$sobj | Add-Member -Name DAGMember -MemberType NoteProperty -Value (IsDAGMember -IsMailbox $sobj.Mailbox -ServerName $svr)
Display-ScriptDebug ("IsMailbox: {0} IsCas: {1} IsHub: {2} IsDAGMember: {3} exVersion: {4} AnyTransportSwitchesEnabled: {5}" -f ($sobj.Mailbox), ($sobj.CAS), ($sobj.Hub), ($sobj.DAGMember), $exVersion, $Script:AnyTransportSwitchesEnabled)
if($Script:AnyTransportSwitchesEnabled -and $sobj.Hub)
{
$sobj | Add-Member -Name TransportInfoCollect -MemberType NoteProperty -Value $true
$sobj | Add-Member -Name TransportInfo -MemberType NoteProperty -Value (Get-TransportLoggingInformationPerServer -Server $svr -version $exVersion )
}
else
{
$sobj | Add-Member -Name TransportInfoCollect -MemberType NoteProperty -Value $false
}
$svrsObject += $sobj
}
$ErrorActionPreference = $oldErrorAction
if (($svrsObject -eq $null) -or ($svrsObject.Count -eq 0))
{
Write-Host("Something wrong happened in Get-ServerObjects stopping script") -ForegroundColor Red
exit
}
Display-ScriptDebug("Function Exit: Get-ServerObjects")
Return $svrsObject
}
Function Get-ArgumentList {
param(
[Parameter(Mandatory=$true)][array]$Servers
)
$obj = New-Object PSCustomObject
$obj | Add-Member -Name FilePath -MemberType NoteProperty -Value $FilePath
$obj | Add-Member -Name ManagedAvailability -MemberType NoteProperty -Value $ManagedAvailability
$obj | Add-Member -Name Zip -MemberType NoteProperty -Value (Get-ZipEnabled)
$obj | Add-Member -Name AppSysLogs -MemberType NoteProperty -Value $AppSysLogs
$obj | Add-Member -Name EWSLogs -MemberType NoteProperty -Value $EWSLogs
$obj | Add-Member -Name DailyPerformanceLogs -MemberType NoteProperty -Value $DailyPerformanceLogs
$obj | Add-Member -Name RPCLogs -MemberType NoteProperty -Value $RPCLogs
$obj | Add-Member -Name EASLogs -MemberType NoteProperty -Value $EASLogs
$obj | Add-Member -Name ECPLogs -MemberType NoteProperty -Value $ECPLogs
$obj | Add-Member -Name AutoDLogs -MemberType NoteProperty -Value $AutoDLogs
$obj | Add-Member -Name OWALogs -MemberType NoteProperty -Value $OWALogs
$obj | Add-Member -Name ADDriverLogs -MemberType NoteProperty -Value $ADDriverLogs
$obj | Add-Member -Name SearchLogs -MemberType NoteProperty -Value $SearchLogs
$obj | Add-Member -Name HighAvailabilityLogs -MemberType NoteProperty -Value $HighAvailabilityLogs
$obj | Add-Member -Name MapiLogs -MemberType NoteProperty -Value $MapiLogs
$obj | Add-Member -Name MessageTrackingLogs -MemberType NoteProperty -Value $MessageTrackingLogs
$obj | Add-Member -Name HubProtocolLogs -MemberType NoteProperty -Value $HubProtocolLogs
$obj | Add-Member -Name HubConnectivityLogs -MemberType NoteProperty -Value $HubConnectivityLogs
$obj | Add-Member -Name FrontEndConnectivityLogs -MemberType NoteProperty -Value $FrontEndConnectivityLogs
$obj | Add-Member -Name FrontEndProtocolLogs -MemberType NoteProperty -Value $FrontEndProtocolLogs
$obj | Add-Member -Name MailboxConnectivityLogs -MemberType NoteProperty -Value $MailboxConnectivityLogs
$obj | Add-Member -Name MailboxProtocolLogs -MemberType NoteProperty -Value $MailboxProtocolLogs
$obj | Add-Member -Name QueueInformationThisServer -MemberType NoteProperty -Value $QueueInformationThisServer
$obj | Add-Member -Name ReceiveConnectors -MemberType NoteProperty -Value $ReceiveConnectors
$obj | Add-Member -Name SendConnectors -MemberType NoteProperty -Value $SendConnectors
$obj | Add-Member -Name DAGInformation -MemberType NoteProperty -Value $DAGInformation
$obj | Add-Member -Name GetVdirs -MemberType NoteProperty -Value $GetVdirs
$obj | Add-Member -Name TransportConfig -MemberType NoteProperty -Value $TransportConfig
$obj | Add-Member -Name DefaultTransportLogging -MemberType NoteProperty -Value $DefaultTransportLogging
$obj | Add-Member -Name ServerInfo -MemberType NoteProperty -Value $ServerInfo
$obj | Add-Member -Name CollectAllLogsBasedOnDaysWorth -MemberType NoteProperty -Value $CollectAllLogsBasedOnDaysWorth
$obj | Add-Member -Name DaysWorth -MemberType NoteProperty -Value $DaysWorth
$obj | Add-Member -Name IISLogs -MemberType NoteProperty -Value $IISLogs
$obj | Add-Member -Name AnyTransportSwitchesEnabled -MemberType NoteProperty -Value $script:AnyTransportSwitchesEnabled
$svrobjs = Get-ServerObjects -ValidServers $Servers
$obj | Add-Member -Name ServerObjects -MemberType NoteProperty -Value $svrobjs
$obj | Add-Member -Name HostExeServerName -MemberType NoteProperty -Value ($env:COMPUTERNAME)
$obj | Add-Member -Name Experfwiz -MemberType NoteProperty -Value $Experfwiz
$obj | Add-Member -Name Experfwiz_LogmanName -MemberType NoteProperty -Value $Experfwiz_LogmanName
$obj | Add-Member -Name Exmon -MemberType NoteProperty -Value $Exmon
$obj | Add-Member -Name Exmon_LogmanName -MemberType NoteProperty -Value $Exmon_LogmanName
$obj | Add-Member -Name ScriptDebug -MemberType NoteProperty -Value $ScriptDebug
#Collect only if enabled we are going to just keep it on the base of the passed parameter object to make it simple
if($GetVdirs)
{
$obj | Add-Member -Name VDirsInfo -MemberType NoteProperty -Value (Get-VdirsLDAP)
}
$mbx = $false
foreach($svr in $svrobjs)
{
if($svr.ServerName -eq $env:COMPUTERNAME)
{
$mbx = $true
$checkSvr = $svr
}
}
if(($mbx) -and ($HighAvailabilityLogs) -and ($checkSvr.DAGMember))
{
Write-Host("Generating cluster logs for the local server's DAG only")
Write-Host("Server: {0}" -f $checkSvr.ServerName)
#Only going to do this for the local server's DAG
$cmd = "Cluster log /g"
Invoke-Expression -Command $cmd | Out-Null
}
if($DAGInformation)
{
$obj | Add-Member -MemberType NoteProperty -Name DAGInfoData -Value (Get-DAGInformation)
}
if($SendConnectors)
{
$value = Get-SendConnector
$obj | Add-Member -MemberType NoteProperty -Name SendConnectorData -Value $value
}
Return $obj
}
Function Test-PossibleCommonScenarios {
#all possible logs
if($AllPossibleLogs)
{
$Script:EWSLogs = $true
$Script:IISLogs = $true
$Script:DailyPerformanceLogs = $true
$Script:ManagedAvailability = $true
$Script:RPCLogs = $true
$Script:EASLogs = $true
$Script:AutoDLogs = $true
$Script:OWALogs = $true
$Script:ADDriverLogs = $true
$Script:HighAvailabilityLogs = $true
$Script:ServerInfo = $true
$Script:GetVdirs = $true
$Script:DAGInformation = $true
$Script:DefaultTransportLogging = $true
$Script:MapiLogs = $true
}
if($DefaultTransportLogging)
{
$Script:HubConnectivityLogs = $true
$Script:MessageTrackingLogs = $true
$Script:QueueInformationThisServer = $true
$Script:SendConnectors = $true
$Script:ReceiveConnectors = $true
$Script:TransportConfig = $true
$Script:FrontEndConnectivityLogs = $true
$Script:MailboxConnectivityLogs = $true
$Script:FrontEndProtocolLogs = $true
}
if($DatabaseFailoverIssue)
{
$Script:DailyPerformanceLogs = $true
$Script:HighAvailabilityLogs = $true
$Script:ManagedAvailability = $true
$Script:DAGInformation = $true
}
#See if any transport logging is enabled.
$Script:AnyTransportSwitchesEnabled = $false
if($HubProtocolLogs -or
$HubConnectivityLogs -or
$MessageTrackingLogs -or
$QueueInformationThisServer -or
$SendConnectors -or
$ReceiveConnectors -or
$TransportConfig -or
$FrontEndConnectivityLogs -or
$FrontEndProtocolLogs -or
$MailboxConnectivityLogs -or
$MailboxProtocolLogs -or
$DefaultTransportLogging){$Script:AnyTransportSwitchesEnabled = $true}
}
Function Test-NoSwitchesProvided {
if($EWSLogs -or
$IISLogs -or
$DailyPerformanceLogs -or
$ManagedAvailability -or
$Experfwiz -or
$RPCLogs -or
$EASLogs -or
$ECPLogs -or
$AutoDLogs -or
$SearchLogs -or
$OWALogs -or
$ADDriverLogs -or
$HighAvailabilityLogs -or
$MapiLogs -or
$Script:AnyTransportSwitchesEnabled -or
$DAGInformation -or
$GetVdirs -or
$Exmon -or
$ServerInfo
){return}
else
{
Write-Host ""
Write-Warning "Doesn't look like any parameters were provided, are you sure you are running the correct command? This is ONLY going to collect the Application and System Logs."
Write-Warning "Enter 'y' to continue and 'n' to stop the script"
do{
$a = Read-Host "Please enter 'y' or 'n'"
}while($a -ne 'y' -and $a -ne 'n')
if($a -eq 'n'){exit}
else{
Write-Host "Okay moving on..."
}
}
}
Function Test-RemoteExecutionOfServers {
param(
[Parameter(Mandatory=$true)][Array]$Server_List
)
Display-ScriptDebug("Function Enter: Test-RemoteExecutionOfServers")
$Servers_up = @()
Write-Host "Checking to see if the servers are up in this list:"
foreach($server in $Server_List) {Write-Host $server}
Write-Host ""
Write-Host "Checking their status...."
foreach($server in $Server_List)
{
Write-Host("Checking server {0}....." -f $server) -NoNewline
if((Test-Connection $server -Quiet))
{
Write-Host "Online" -ForegroundColor Green
$Servers_up += $server
}
else
{
Write-Host "Offline" -ForegroundColor Red
Write-Host ("Removing Server {0} from the list to collect data from" -f $server)
}
}
#Now we should check to see if can use WRM with invoke-command
Write-Host ""
Write-Host "For all the servers that are up, we are going to see if remote execution will work"
#shouldn't need to test if they are Exchange servers, as we should be doing that locally as well.
$valid_Servers = @()
$oldErrorAction = $ErrorActionPreference
$ErrorActionPreference = "Stop"
foreach($server in $Servers_up)
{
try {
Write-Host("Checking Server {0}....." -f $server) -NoNewLine
Invoke-Command -ComputerName $server -ScriptBlock { Get-Process | Out-Null}
#if that doesn't fail, we should be okay to add it to the working list
Write-Host("Passed") -ForegroundColor Green
$valid_Servers += $server
}
catch {
Write-Host("Failed") -ForegroundColor Red
Write-Host("Removing Server {0} from the list to collect data from" -f $server)
}
}
Display-ScriptDebug("Function Exit: Test-RemoteExecutionOfServers")
$ErrorActionPreference = $oldErrorAction
return $valid_Servers
}
Function Get-VdirsLDAP {
$authTypeEnum = @"
namespace AuthMethods
{
using System;
[Flags]
public enum AuthenticationMethodFlags
{
None = 0,
Basic = 1,
Ntlm = 2,
Fba = 4,
Digest = 8,
WindowsIntegrated = 16,
LiveIdFba = 32,
LiveIdBasic = 64,
WSSecurity = 128,
Certificate = 256,
NegoEx = 512,
// Exchange 2013
OAuth = 1024,
Adfs = 2048,
Kerberos = 4096,
Negotiate = 8192,
LiveIdNegotiate = 16384,
}
}
"@
Write-Host "Collecting Virtual Directory Information..."
Add-Type -TypeDefinition $authTypeEnum -Language CSharp
$objRootDSE = [ADSI]"LDAP://rootDSE"
$strConfigurationNC = $objRootDSE.configurationNamingContext
$objConfigurationNC = New-object System.DirectoryServices.DirectoryEntry("LDAP://$strConfigurationNC")
$searcher = new-object DirectoryServices.DirectorySearcher
$searcher.filter = "(&(objectClass=msExchVirtualDirectory)(!objectClass=container))"
$searcher.SearchRoot = $objConfigurationNC
$Searcher.CacheResults = $false
$Searcher.SearchScope = "Subtree"
$Searcher.PageSize = 1000
# Get all the results
$colResults = $searcher.FindAll()
$objects = @()
# Loop through the results and
foreach ($objResult in $colResults)
{
$objItem = $objResult.getDirectoryEntry()
$objProps = $objItem.Properties
$place = $objResult.Path.IndexOf("CN=Protocols,CN=")
$ServerDN = [ADSI]("LDAP://" + $objResult.Path.SubString($place,($objResult.Path.Length - $place)).Replace("CN=Protocols,",""))
[string]$Site = $serverDN.Properties.msExchServerSite.ToString().Split(",")[0].Replace("CN=","")
[string]$server = $serverDN.Properties.adminDisplayName.ToString()
[string]$version = $serverDN.Properties.serialNumber.ToString()
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -name Server -value $server
$obj | Add-Member -MemberType NoteProperty -name Version -value $version
$obj | Add-Member -MemberType NoteProperty -name Site -value $Site
[string]$var = $objProps.DistinguishedName.ToString().Split(",")[0].Replace("CN=","")
$obj | Add-Member -MemberType NoteProperty -name VirtualDirectory -value $var
[string]$var = $objProps.msExchInternalHostName
$obj | Add-Member -MemberType NoteProperty -name InternalURL -value $var
if (-not [string]::IsNullOrEmpty($objProps.msExchInternalAuthenticationMethods))
{
$obj | Add-Member -MemberType NoteProperty -name InternalAuthenticationMethods -value ([AuthMethods.AuthenticationMethodFlags]$objProps.msExchInternalAuthenticationMethods)
}
else
{
$obj | Add-Member -MemberType NoteProperty -name InternalAuthenticationMethods -value $null
}
[string]$var = $objProps.msExchExternalHostName
$obj | Add-Member -MemberType NoteProperty -name ExternalURL -value $var
if (-not [string]::IsNullOrEmpty($objProps.msExchExternalAuthenticationMethods))
{
$obj | Add-Member -MemberType NoteProperty -name ExternalAuthenticationMethods -value ([AuthMethods.AuthenticationMethodFlags]$objProps.msExchExternalAuthenticationMethods)
}
else
{
$obj | Add-Member -MemberType NoteProperty -name ExternalAuthenticationMethods -value $null
}
if (-not [string]::IsNullOrEmpty($objProps.msExch2003Url))
{
[string]$var = $objProps.msExch2003Url
$obj | Add-Member -MemberType NoteProperty -name Exchange2003URL -value $var
}
else
{
$obj | Add-Member -MemberType NoteProperty -name Exchange2003URL -value $null
}
[Array]$objects += $obj
}
return $objects
}
Function Get-ExchangeServerDAGName {
param(
[string]$Server
)
Display-ScriptDebug("Function Enter: Get-ExchangeServerDAGName")
$oldErrorAction = $ErrorActionPreference
$ErrorActionPreference = "Stop"
try {
$dagName = (Get-MailboxServer $Server).DatabaseAvailabilityGroup.Name
Display-ScriptDebug("Returning dagName: {0}" -f $dagName)
Display-ScriptDebug("Function Exit: Get-ExchangeServerDAGName")
return $dagName
}
catch {
Write-Host("Looks like this server {0} isn't a Mailbox Server. Unable to get DAG Infomration." -f $Server)
return $null
}
finally
{
$ErrorActionPreference = $oldErrorAction
}
}
Function Get-MailboxDatabaseInformationFromDAG{
param(
[parameter(Mandatory=$true)]$DAGInfo
)
Display-ScriptDebug("Function Enter: Get-MailboxDatabaseInformationFromDAG")
Write-Host("Getting Database information from {0} DAG member servers" -f $DAGInfo.Name)
$AllDupMDB = @()
foreach($serverobj in $DAGInfo.Servers)
{
foreach($server in $serverobj.Name)
{
$AllDupMDB += Get-MailboxDatabase -Server $server -Status
}
}
#remove all dups
$MailboxDBS = @()
foreach($t_mdb in $AllDupMDB)
{
$add = $true
foreach($mdb in $MailboxDBS)
{
if($mdb.Name -eq $t_mdb.Name)
{
$add = $false
break
}
}
if($add)
{
$MailboxDBS += $t_mdb
}
}
Write-Host("Found the following databases:")
foreach($mdb in $MailboxDBS)
{
Write-Host($mdb)
}
$MailboxDBInfo = @()
foreach($mdb in $MailboxDBS)
{
$mdb_Name = $mdb.Name
$dbObj = New-Object PSCustomObject
$dbObj | Add-Member -MemberType NoteProperty -Name MDBName -Value $mdb_Name
$dbObj | Add-Member -MemberType NoteProperty -Name MDBInfo -Value $mdb
$value = Get-MailboxDatabaseCopyStatus $mdb_Name\*
$dbObj | Add-Member -MemberType NoteProperty -Name MDBCopyStatus -Value $value
$MailboxDBInfo += $dbObj
}
Display-ScriptDebug("Function Exit: Get-MailboxDatabaseInformationFromDAG")
return $MailboxDBInfo
}
Function Get-DAGInformation {
$DAGName = Get-ExchangeServerDAGName -Server $env:COMPUTERNAME #only going to get the local server's DAG info
if($DAGName -ne $null)
{
$dagObj = New-Object PSCustomObject
$value = Get-DatabaseAvailabilityGroup $DAGName -Status
$dagObj | Add-Member -MemberType NoteProperty -Name DAGInfo -Value $value
$value = Get-DatabaseAvailabilityGroupNetwork $DAGName
$dagObj | Add-Member -MemberType NoteProperty -Name DAGNetworkInfo -Value $value
$dagObj | Add-Member -MemberType NoteProperty -Name AllMdbs -Value (Get-MailboxDatabaseInformationFromDAG -DAGInfo $dagObj.DAGInfo)
return $dagObj
}
}
#Logic for determining the free space on the drive
Function Get-FreeSpaceFromDrives {
param(
[Parameter(Mandatory=$true)][string]$Root_Full_Path,
[Parameter(Mandatory=$true)][Array]$Drives_WMI
)
$driveLetter = ($Root_Full_Path.Split("\"))[0]
$Free_Space = $Drives_WMI | ?{$_.DriveLetter -eq $driveLetter} | select DriveLetter, label, @{LABEL='GBfreespace';EXPRESSION={$_.freespace/1GB}}
return $Free_Space
}
Function Get-DisksData {
$drives = gwmi win32_volume -Filter 'drivetype = 3'
$obj = New-Object PSCustomObject
$obj | Add-Member -MemberType NoteProperty -Name Drives -Value $drives
$obj | Add-Member -MemberType NoteProperty -Name ServerName -Value ($env:COMPUTERNAME)
return $obj
}
Function Test-DiskSpace {
param(
[Parameter(Mandatory=$true)][array]$Servers,
[Parameter(Mandatory=$true)][string]$Path,
[Parameter(Mandatory=$true)][int]$CheckSize
)
Display-ScriptDebug("Function Enter: Test-DiskSpace")
Display-ScriptDebug("Passed - Path: {0} CheckSize: {1}" -f $Path, $CheckSize)
Write-Host("Checking the free space on the servers before collecting the data...")
$script_block = ${Function:Get-DisksData}
$Servers_Data = Invoke-Command -ComputerName $Servers -ScriptBlock $script_block
$Passed_Servers = @()
foreach($server in $Servers_Data)
{
$Free_Space = Get-FreeSpaceFromDrives -Root_Full_Path $Path -Drives_WMI $server.Drives
if($Free_Space.GBfreespace -gt $CheckSize)
{
Write-Host("[{0}] : We have more than {1} GB of free space at {2}" -f $server.ServerName, $CheckSize, $Path)
$Passed_Servers += $server.ServerName
}
else
{
Write-Host("[{0}] : We have less than {1} GB of free space on {2}" -f $server.ServerName, $CheckSize, $Path)
}
}
if($Passed_Servers.Count -ne $Servers.Count)
{
Write-Host("Looks like all the servers didn't pass the disk space check.")
Write-Host("We will only collect data from these servers: ")
foreach($svr in $Passed_Servers)
{
Write-Host("{0}" -f $svr)
}
do{
$r = Read-Host("Are you sure you want to continue? 'y' or 'n'")
}while($r -ne 'y' -and $r -ne 'n')
if($r -eq 'n')
{
exit
}
}
Display-ScriptDebug("Function Exit: Test-DiskSpace")
return $Passed_Servers
}
Function Get-RemoteLogLocation {
param(
[parameter(Mandatory=$true)][array]$Servers,
[parameter(Mandatory=$true)][string]$RootPath
)
Function Get-ZipLocation
{
param(
[parameter(Mandatory=$true)][string]$RootPath
)
$like = "*-{0}*.zip" -f (Get-Date -Format Md)
$Item = $RootPath + (Get-ChildItem $RootPath | ?{$_.Name -like $like} | sort CreationTime -Descending)[0]
$obj = New-Object -TypeName PSCustomObject
$obj | Add-Member -MemberType NoteProperty -Name ServerName -Value $env:COMPUTERNAME
$obj | Add-Member -MemberType NoteProperty -Name ZipFolder -Value $Item
$obj | Add-Member -MemberType NoteProperty -Name Size -Value ((Get-Item $Item).Length)
return $obj
}
$script_block = ${function:Get-ZipLocation}
$LogInfo = Invoke-Command -ComputerName $Servers -ScriptBlock $script_block -ArgumentList $RootPath
return $LogInfo
}
Function Test-DiskSpaceForCopyOver {
param(
[parameter(Mandatory=$true)][array]$LogPathObject,
[parameter(Mandatory=$true)][string]$RootPath
)
Display-ScriptDebug("Function Enter: Test-DiskSpaceForCopyOver")
foreach($SvrObj in $LogPathObject)
{