forked from Lucifer1993/PLtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealthChecker.ps1
5839 lines (5205 loc) · 273 KB
/
HealthChecker.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: HealthChecker.ps1
Original Author: Marc Nivens
Author: David Paulson
Contributor: Jason Shinbaum, Michael Schatte, Lukas Sassl
Requires: Exchange Management Shell and administrator rights on the target Exchange
server as well as the local machine.
Major Release History:
11/10/2020 - Initial Public Release of version 3.
1/18/2017 - Initial Public Release of version 2. - rewritten by David Paulson.
3/30/2015 - Initial Public Release.
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
Checks the target Exchange server for various configuration recommendations from the Exchange product group.
.DESCRIPTION
This script checks the Exchange server for various configuration recommendations outlined in the
"Exchange 2013 Performance Recommendations" section on Microsoft Docs, found here:
https://docs.microsoft.com/en-us/exchange/exchange-2013-sizing-and-configuration-recommendations-exchange-2013-help
Informational items are reported in Grey. Settings found to match the recommendations are
reported in Green. Warnings are reported in yellow. Settings that can cause performance
problems are reported in red. Please note that most of these recommendations only apply to Exchange
2013/2016. The script will run against Exchange 2010/2007 but the output is more limited.
.PARAMETER Server
This optional parameter allows the target Exchange server to be specified. If it is not the
local server is assumed.
.PARAMETER OutputFilePath
This optional parameter allows an output directory to be specified. If it is not the local
directory is assumed. This parameter must not end in a \. To specify the folder "logs" on
the root of the E: drive you would use "-OutputFilePath E:\logs", not "-OutputFilePath E:\logs\".
.PARAMETER MailboxReport
This optional parameter gives a report of the number of active and passive databases and
mailboxes on the server.
.PARAMETER LoadBalancingReport
This optional parameter will check the connection count of the Default Web Site for every server
running Exchange 2013/2016 with the Client Access role in the org. It then breaks down servers by percentage to
give you an idea of how well the load is being balanced.
.PARAMETER CasServerList
Used with -LoadBalancingReport. A comma separated list of CAS servers to operate against. Without
this switch the report will use all 2013/2016 Client Access servers in the organization.
.PARAMETER SiteName
Used with -LoadBalancingReport. Specifies a site to pull CAS servers from instead of querying every server
in the organization.
.PARAMETER XMLDirectoryPath
Used in combination with BuildHtmlServersReport switch for the location of the HealthChecker XML files for servers
which you want to be included in the report. Default location is the current directory.
.PARAMETER BuildHtmlServersReport
Switch to enable the script to build the HTML report for all the servers XML results in the XMLDirectoryPath location.
.PARAMETER HtmlReportFile
Name of the HTML output file from the BuildHtmlServersReport. Default is ExchangeAllServersReport.html
.PARAMETER DCCoreRatio
Gathers the Exchange to DC/GC Core ratio and displays the results in the current site that the script is running in.
.PARAMETER Verbose
This optional parameter enables verbose logging.
.EXAMPLE
.\HealthChecker.ps1 -Server SERVERNAME
Run against a single remote Exchange server
.EXAMPLE
.\HealthChecker.ps1 -Server SERVERNAME -MailboxReport -Verbose
Run against a single remote Exchange server with verbose logging and mailbox report enabled.
.EXAMPLE
Get-ExchangeServer | ?{$_.AdminDisplayVersion -Match "^Version 15"} | %{.\HealthChecker.ps1 -Server $_.Name}
Run against all Exchange 2013/2016 servers in the Organization.
.EXAMPLE
.\HealthChecker.ps1 -LoadBalancingReport
Run a load balancing report comparing all Exchange 2013/2016 CAS servers in the Organization.
.EXAMPLE
.\HealthChecker.ps1 -LoadBalancingReport -CasServerList CAS01,CAS02,CAS03
Run a load balancing report comparing servers named CAS01, CAS02, and CAS03.
.LINK
https://docs.microsoft.com/en-us/exchange/exchange-2013-sizing-and-configuration-recommendations-exchange-2013-help
https://docs.microsoft.com/en-us/exchange/exchange-2013-virtualization-exchange-2013-help#requirements-for-hardware-virtualization
https://docs.microsoft.com/en-us/exchange/plan-and-deploy/virtualization?view=exchserver-2019#requirements-for-hardware-virtualization
#>
[CmdletBinding(DefaultParameterSetName="HealthChecker")]
param(
[Parameter(Mandatory=$false,ParameterSetName="HealthChecker")]
[Parameter(Mandatory=$false,ParameterSetName="MailboxReport")]
[string]$Server=($env:COMPUTERNAME),
[Parameter(Mandatory=$false)]
[ValidateScript({-not $_.ToString().EndsWith('\')})][string]$OutputFilePath = ".",
[Parameter(Mandatory=$false,ParameterSetName="MailboxReport")]
[switch]$MailboxReport,
[Parameter(Mandatory=$false,ParameterSetName="LoadBalancingReport")]
[switch]$LoadBalancingReport,
[Parameter(Mandatory=$false,ParameterSetName="LoadBalancingReport")]
[array]$CasServerList = $null,
[Parameter(Mandatory=$false,ParameterSetName="LoadBalancingReport")]
[string]$SiteName = ([string]::Empty),
[Parameter(Mandatory=$false,ParameterSetName="HTMLReport")]
[Parameter(Mandatory=$false,ParameterSetName="AnalyzeDataOnly")]
[ValidateScript({-not $_.ToString().EndsWith('\')})][string]$XMLDirectoryPath = ".",
[Parameter(Mandatory=$false,ParameterSetName="HTMLReport")]
[switch]$BuildHtmlServersReport,
[Parameter(Mandatory=$false,ParameterSetName="HTMLReport")]
[string]$HtmlReportFile="ExchangeAllServersReport.html",
[Parameter(Mandatory=$false,ParameterSetName="DCCoreReport")]
[switch]$DCCoreRatio,
[Parameter(Mandatory=$false,ParameterSetName="AnalyzeDataOnly")]
[switch]$AnalyzeDataOnly,
[Parameter(Mandatory=$false)][switch]$SaveDebugLog
)
$healthCheckerVersion = "3.1.1"
$VirtualizationWarning = @"
Virtual Machine detected. Certain settings about the host hardware cannot be detected from the virtual machine. Verify on the VM Host that:
- There is no more than a 1:1 Physical Core to Virtual CPU ratio (no oversubscribing)
- If Hyper-Threading is enabled do NOT count Hyper-Threaded cores as physical cores
- Do not oversubscribe memory or use dynamic memory allocation
Although Exchange technically supports up to a 2:1 physical core to vCPU ratio, a 1:1 ratio is strongly recommended for performance reasons. Certain third party Hyper-Visors such as VMWare have their own guidance.
VMWare recommends a 1:1 ratio. Their guidance can be found at https://www.vmware.com/files/pdf/Exchange_2013_on_VMware_Best_Practices_Guide.pdf.
Related specifically to VMWare, if you notice you are experiencing packet loss on your VMXNET3 adapter, you may want to review the following article from VMWare: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2039495.
For further details, please review the virtualization recommendations on Microsoft Docs at the following locations:
Exchange 2013: https://docs.microsoft.com/en-us/exchange/exchange-2013-virtualization-exchange-2013-help#requirements-for-hardware-virtualization.
Exchange 2016/2019: https://docs.microsoft.com/en-us/exchange/plan-and-deploy/virtualization?view=exchserver-2019.
"@
#this is to set the verbose information to a different color
if($PSBoundParameters["Verbose"]){
#Write verose output in cyan since we already use yellow for warnings
$Script:VerboseEnabled = $true
$VerboseForeground = $Host.PrivateData.VerboseForegroundColor
$Host.PrivateData.VerboseForegroundColor = "Cyan"
}
try {
#Enums and custom data types
Add-Type -TypeDefinition @"
using System;
using System.Collections;
namespace HealthChecker
{
public class HealthCheckerExchangeServer
{
public string ServerName; //String of the server that we are working with
public HardwareInformation HardwareInformation; // Hardware Object Information
public OperatingSystemInformation OSInformation; // OS Version Object Information
public ExchangeInformation ExchangeInformation; //Detailed Exchange Information
public string HealthCheckerVersion; //To determine the version of the script on the object.
}
// ExchangeInformation
public class ExchangeInformation
{
public ExchangeBuildInformation BuildInformation = new ExchangeBuildInformation(); //Exchange build information
public object GetExchangeServer; //Stores the Get-ExchangeServer Object
public ExchangeNetFrameworkInformation NETFramework = new ExchangeNetFrameworkInformation();
public bool MapiHttpEnabled; //Stored from organization config
public string ExchangeServicesNotRunning; //Contains the Exchange services not running by Test-ServiceHealth
public Hashtable ApplicationPools;
public ExchangeRegistryValues RegistryValues = new ExchangeRegistryValues();
public ExchangeServerMaintenance ServerMaintenance;
public System.Array ExchangeCertificates; //stores all the Exchange certificates on the servers.
}
public class ExchangeBuildInformation
{
public ExchangeServerRole ServerRole; //Roles that are currently set and installed.
public ExchangeMajorVersion MajorVersion; //Exchange Version (Exchange 2010/2013/2019)
public ExchangeCULevel CU; // Exchange CU Level
public string FriendlyName; //Exchange Friendly Name is provided
public string BuildNumber; //Exchange Build Number
public string ReleaseDate; // Exchange release date for which the CU they are currently on
public bool SupportedBuild; //Determines if we are within the correct build of Exchange.
public object ExchangeSetup; //Stores the Get-Command ExSetup object
public System.Array KBsInstalled; //Stored object IU or Security KB fixes
}
public class ExchangeNetFrameworkInformation
{
public NetMajorVersion MinSupportedVersion; //Min Supported .NET Framework version
public NetMajorVersion MaxSupportedVersion; //Max (Recommended) Supported .NET version.
public bool OnRecommendedVersion; //RecommendedNetVersion Info includes all the factors. Windows Version & CU.
public string DisplayWording; //Display if we are in Support or not
}
public class ExchangeServerMaintenance
{
public System.Array InactiveComponents;
public object GetServerComponentState;
public object GetClusterNode;
public object GetMailboxServer;
}
//enum for CU levels of Exchange
public enum ExchangeCULevel
{
Unknown,
Preview,
RTM,
CU1,
CU2,
CU3,
CU4,
CU5,
CU6,
CU7,
CU8,
CU9,
CU10,
CU11,
CU12,
CU13,
CU14,
CU15,
CU16,
CU17,
CU18,
CU19,
CU20,
CU21,
CU22,
CU23
}
//enum for the server roles that the computer is
public enum ExchangeServerRole
{
MultiRole,
Mailbox,
ClientAccess,
Hub,
Edge,
None
}
//enum for the Exchange version
public enum ExchangeMajorVersion
{
Unknown,
Exchange2010,
Exchange2013,
Exchange2016,
Exchange2019
}
public class ExchangeRegistryValues
{
public int CtsProcessorAffinityPercentage; //Stores the CtsProcessorAffinityPercentage registry value from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ExchangeServer\v15\Search\SystemParameters
}
// End ExchangeInformation
// OperatingSystemInformation
public class OperatingSystemInformation
{
public OSBuildInformation BuildInformation = new OSBuildInformation(); // contains build information
public NetworkInformation NetworkInformation = new NetworkInformation(); //stores network information and settings
public PowerPlanInformation PowerPlan = new PowerPlanInformation(); //stores the power plan information
public PageFileInformation PageFile; //stores the page file information
public LmCompatibilityLevelInformation LmCompatibility; // stores Lm Compatibility Level Information
public bool ServerPendingReboot; // determines if the server is pending a reboot. TODO: Adjust to contain the registry values that we are looking at.
public TimeZoneInformation TimeZone = new TimeZoneInformation(); //stores time zone information
public Hashtable TLSSettings; // stores the TLS settings on the server.
public InstalledUpdatesInformation InstalledUpdates = new InstalledUpdatesInformation(); //store the install update
public ServerBootUpInformation ServerBootUp = new ServerBootUpInformation(); // stores the server boot up time information
public System.Array VcRedistributable; //stores the Visual C++ Redistributable
public OSNetFrameworkInformation NETFramework = new OSNetFrameworkInformation(); //stores OS Net Framework
public bool CredentialGuardEnabled;
public OSRegistryValues RegistryValues = new OSRegistryValues();
public Smb1ServerSettings Smb1ServerSettings = new Smb1ServerSettings();
}
public class OSBuildInformation
{
public OSServerVersion MajorVersion; //OS Major Version
public string VersionBuild; //hold the build number
public string FriendlyName; //string holder of the Windows Server friendly name
public object OperatingSystem; // holds Win32_OperatingSystem
}
public class NetworkInformation
{
public double TCPKeepAlive; // value used for the TCP/IP keep alive value in the registry
public double RpcMinConnectionTimeout; //holds the value for the RPC minimum connection timeout.
public string HttpProxy; // holds the setting for HttpProxy if one is set.
public object PacketsReceivedDiscarded; //hold all the packets received discarded on the server.
public double IPv6DisabledComponents; //value stored in the registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\DisabledComponents
public bool IPv6DisabledOnNICs; //value that determines if we have IPv6 disabled on some NICs or not.
public System.Array NetworkAdapters; //stores all the NICs on the servers.
public string PnPCapabilities; //Value from PnPCapabilities registry
public bool SleepyNicDisabled; //If the NIC can be in power saver mode by the OS.
}
public class PowerPlanInformation
{
public bool HighPerformanceSet; // If the power plan is High Performance
public string PowerPlanSetting; //value for the power plan that is set
public object PowerPlan; //object to store the power plan information
}
public class PageFileInformation
{
public object PageFile; //store the information that we got for the page file
public double MaxPageSize; //holds the information of what our page file is set to
}
public class OSRegistryValues
{
public int CurrentVersionUbr; // stores SOFTWARE\Microsoft\Windows NT\CurrentVersion\UBR
public int LanManServerDisabledCompression; // stores SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\DisabledCompression
}
public class LmCompatibilityLevelInformation
{
public int RegistryValue; //The LmCompatibilityLevel for the server (INT 1 - 5)
public string Description; //description of the LmCompat that the server is set to
}
public class TimeZoneInformation
{
public string CurrentTimeZone; //stores the value for the current time zone of the server.
public int DynamicDaylightTimeDisabled; // the registry value for DynamicDaylightTimeDisabled.
public string TimeZoneKeyName; // the registry value TimeZoneKeyName.
public string StandardStart; // the registry value for StandardStart.
public string DaylightStart; // the registry value for DaylightStart.
public bool DstIssueDetected; // Determines if there is a high chance of an issue.
public System.Array ActionsToTake; //array of verbage of the issues detected.
}
public class ServerRebootInformation
{
public bool PendingFileRenameOperations; //bool "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\" item PendingFileRenameOperations.
public object SccmReboot; // object to store CimMethod for class name CCM_ClientUtilities
public bool SccmRebootPending; // SccmReboot has either PendingReboot or IsHardRebootPending is set to true.
public bool ComponentBasedServicingPendingReboot; // bool HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending
public bool AutoUpdatePendingReboot; // bool HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired
public bool PendingReboot; // bool if reboot types are set to true
}
public class InstalledUpdatesInformation
{
public System.Array HotFixes; //array to keep all the hotfixes of the server
public System.Array HotFixInfo; //object to store hotfix information
public System.Array InstalledUpdates; //store the install updates
}
public class ServerBootUpInformation
{
public string Days;
public string Hours;
public string Minutes;
public string Seconds;
}
//enum for the dword values of the latest supported VC++ redistributable releases
//https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
public enum VCRedistVersion
{
Unknown = 0,
VCRedist2012 = 184610406,
VCRedist2013 = 201367256
}
public class SoftwareInformation
{
public string DisplayName;
public string DisplayVersion;
public string InstallDate;
public int VersionIdentifier;
}
public class OSNetFrameworkInformation
{
public NetMajorVersion NetMajorVersion; //NetMajorVersion value
public string FriendlyName; //string of the friendly name
public int RegistryValue; //store the registry value
public Hashtable FileInformation; //stores Get-Item information for .NET Framework
}
//enum for the OSServerVersion that we are
public enum OSServerVersion
{
Unknown,
Windows2008,
Windows2008R2,
Windows2012,
Windows2012R2,
Windows2016,
Windows2019,
WindowsCore
}
//enum for the dword value of the .NET frame 4 that we are on
public enum NetMajorVersion
{
Unknown = 0,
Net4d5 = 378389,
Net4d5d1 = 378675,
Net4d5d2 = 379893,
Net4d5d2wFix = 380035,
Net4d6 = 393295,
Net4d6d1 = 394254,
Net4d6d1wFix = 394294,
Net4d6d2 = 394802,
Net4d7 = 460798,
Net4d7d1 = 461308,
Net4d7d2 = 461808,
Net4d8 = 528040
}
public class Smb1ServerSettings
{
public object RegistryValue;
public object SmbServerConfiguration;
public object WindowsFeature;
public int Smb1Status;
}
// End OperatingSystemInformation
// HardwareInformation
public class HardwareInformation
{
public string Manufacturer; //String to display the hardware information
public ServerType ServerType; //Enum to determine if the hardware is VMware, HyperV, Physical, or Unknown
public double TotalMemory; //Stores the total memory available
public object System; //object to store the system information that we have collected
public ProcessorInformation Processor; //Detailed processor Information
public bool AutoPageFile; //True/False if we are using a page file that is being automatically set
public string Model; //string to display Model
}
//enum for the type of computer that we are
public enum ServerType
{
VMWare,
AmazonEC2,
HyperV,
Physical,
Unknown
}
public class ProcessorInformation
{
public string Name; //String of the processor name
public int NumberOfPhysicalCores; //Number of Physical cores that we have
public int NumberOfLogicalCores; //Number of Logical cores that we have presented to the os
public int NumberOfProcessors; //Total number of processors that we have in the system
public int MaxMegacyclesPerCore; //Max speed that we can get out of the cores
public int CurrentMegacyclesPerCore; //Current speed that we are using the cores at
public bool ProcessorIsThrottled; //True/False if we are throttling our processor
public bool DifferentProcessorsDetected; //true/false to detect if we have different processor types detected
public bool DifferentProcessorCoreCountDetected; //detect if there are a different number of core counts per Processor CPU socket
public int EnvironmentProcessorCount; //[system.environment]::processorcount
public object ProcessorClassObject; // object to store the processor information
}
//HTML & display classes
public class HtmlServerValues
{
public System.Array OverviewValues;
public System.Array ActionItems; //use HtmlServerActionItemRow
public System.Array ServerDetails; // use HtmlServerInformationRow
}
public class HtmlServerActionItemRow
{
public string Setting;
public string DetailValue;
public string RecommendedDetails;
public string MoreInformation;
public string Class;
}
public class HtmlServerInformationRow
{
public string Name;
public string DetailValue;
public string Class;
}
public class DisplayResultsLineInfo
{
public string DisplayValue;
public string Name;
public int TabNumber;
public object TestingValue; //Used for pester testing down the road.
public string WriteType;
public string Line
{
get
{
if (String.IsNullOrEmpty(this.Name))
{
return this.DisplayValue;
}
return String.Concat(this.Name, ": ", this.DisplayValue);
}
}
}
public class DisplayResultsGroupingKey
{
public string Name;
public int DefaultTabNumber;
public bool DisplayGroupName;
public int DisplayOrder;
}
public class AnalyzedInformation
{
public HealthCheckerExchangeServer HealthCheckerExchangeServer;
public Hashtable HtmlServerValues = new Hashtable();
public Hashtable DisplayResults = new Hashtable();
}
}
"@ -ErrorAction Stop
}
catch
{
Write-Warning "There was an error trying to add custom classes to the current PowerShell session. You need to close this session and open a new one to have the script properly work."
exit
}
function Write-Red($message)
{
Write-DebugLog $message
Write-Host $message -ForegroundColor Red
$message | Out-File ($OutputFullPath) -Append
}
function Write-Yellow($message)
{
Write-DebugLog $message
Write-Host $message -ForegroundColor Yellow
$message | Out-File ($OutputFullPath) -Append
}
function Write-Green($message)
{
Write-DebugLog $message
Write-Host $message -ForegroundColor Green
$message | Out-File ($OutputFullPath) -Append
}
function Write-Grey($message)
{
Write-DebugLog $message
Write-Host $message
$message | Out-File ($OutputFullPath) -Append
}
function Write-VerboseOutput($message)
{
Write-Verbose $message
Write-DebugLog $message
if($Script:VerboseEnabled)
{
$message | Out-File ($OutputFullPath) -Append
}
}
function Write-DebugLog($message)
{
if(![string]::IsNullOrEmpty($message))
{
$Script:Logger.WriteToFileOnly($message)
}
}
Function Write-Break {
Write-Host ""
}
#Function Version 1.1
Function Write-HostWriter {
param(
[Parameter(Mandatory=$true)][string]$WriteString
)
if($Script:Logger -ne $null)
{
$Script:Logger.WriteHost($WriteString)
}
elseif($HostFunctionCaller -eq $null)
{
Write-Host $WriteString
}
else
{
&$HostFunctionCaller $WriteString
}
}
Function Write-VerboseWriter {
param(
[Parameter(Mandatory=$true)][string]$WriteString
)
if($VerboseFunctionCaller -eq $null)
{
Write-Verbose $WriteString
}
else
{
&$VerboseFunctionCaller $WriteString
}
}
$Script:VerboseFunctionCaller = ${Function:Write-VerboseOutput}
#Function Version 1.0
Function Write-ScriptMethodHostWriter{
param(
[Parameter(Mandatory=$true)][string]$WriteString
)
if($this.LoggerObject -ne $null)
{
$this.LoggerObject.WriteHost($WriteString)
}
elseif($this.HostFunctionCaller -eq $null)
{
Write-Host $WriteString
}
else
{
$this.HostFunctionCaller($WriteString)
}
}
#Function Version 1.0
Function Write-ScriptMethodVerboseWriter {
param(
[Parameter(Mandatory=$true)][string]$WriteString
)
if($this.LoggerObject -ne $null)
{
$this.LoggerObject.WriteVerbose($WriteString)
}
elseif($this.VerboseFunctionCaller -eq $null -and
$this.WriteVerboseData)
{
Write-Host $WriteString -ForegroundColor Cyan
}
elseif($this.WriteVerboseData)
{
$this.VerboseFunctionCaller($WriteString)
}
}
Function Write-HealthCheckerVersion {
$currentVersion = Test-ScriptVersion -ApiUri "api.github.com" -RepoOwner "dpaulson45" `
-RepoName "HealthChecker" `
-CurrentVersion $healthCheckerVersion `
-DaysOldLimit 90 `
-CatchActionFunction ${Function:Invoke-CatchActions}
$Script:DisplayedScriptVersionAlready = $true
if($currentVersion)
{
Write-Green("Exchange Health Checker version {0}" -f $healthCheckerVersion)
}
else
{
Write-Yellow("Exchange Health Checker version {0}. This script is probably outdated. Please verify before relying on the results." -f $healthCheckerVersion)
}
}
Function Write-ResultsToScreen {
param(
[Hashtable]$ResultsToWrite
)
Write-VerboseOutput("Calling: Write-ResultsToScreen")
$indexOrderGroupingToKey = @{}
foreach ($keyGrouping in $ResultsToWrite.Keys)
{
$indexOrderGroupingToKey[$keyGrouping.DisplayOrder] = $keyGrouping
}
$sortedIndexOrderGroupingToKey = $indexOrderGroupingToKey.Keys | Sort-Object
foreach ($key in $sortedIndexOrderGroupingToKey)
{
Write-VerboseOutput("Working on Key: {0}" -f $key)
$keyGrouping = $indexOrderGroupingToKey[$key]
Write-VerboseOutput("Working on Key Group: {0}" -f $keyGrouping.Name)
Write-VerboseOutput("Total lines to write: {0}" -f ($ResultsToWrite[$keyGrouping].Count))
if ($keyGrouping.DisplayGroupName)
{
Write-Grey($keyGrouping.Name)
$dashes = [string]::empty
1..($keyGrouping.Name.Length) | %{$dashes = $dashes + "-"}
Write-Grey($dashes)
}
foreach ($line in $ResultsToWrite[$keyGrouping])
{
$tab = [string]::Empty
if ($line.TabNumber -ne 0)
{
1..($line.TabNumber) | %{$tab = $tab + "`t"}
}
$writeValue = "{0}{1}" -f $tab, $line.Line
switch ($line.WriteType)
{
"Grey" {Write-Grey($writeValue)}
"Yellow" {Write-Yellow($writeValue)}
"Green" {Write-Green($writeValue)}
"Red" {Write-Red($writeValue)}
}
}
Write-Grey("")
}
}
#Master Template: https://raw.githubusercontent.com/dpaulson45/PublicPowerShellScripts/master/Functions/Get-AllNicInformation/Get-AllNicInformation.ps1
Function Get-AllNicInformation {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)][string]$ComputerName,
[Parameter(Mandatory=$false)][string]$ComputerFQDN,
[Parameter(Mandatory=$false)][scriptblock]$CatchActionFunction
)
#Function Version 1.6
<#
Required Functions:
https://raw.githubusercontent.com/dpaulson45/PublicPowerShellScripts/master/Functions/Write-VerboseWriters/Write-VerboseWriter.ps1
https://raw.githubusercontent.com/dpaulson45/PublicPowerShellScripts/master/Functions/Get-WmiObjectHandler/Get-WmiObjectHandler.ps1
https://raw.githubusercontent.com/dpaulson45/PublicPowerShellScripts/master/Functions/Invoke-RegistryGetValue/Invoke-RegistryGetValue.ps1
#>
Write-VerboseWriter("Calling: Get-AllNicInformation")
Write-VerboseWriter("Passed [string]ComputerName: {0} | [string]ComputerFQDN: {1}" -f $ComputerName, $ComputerFQDN)
Function Get-NicPnpCapabilitiesSetting {
[CmdletBinding()]
param(
[string]$NicAdapterComponentId
)
if ($NicAdapterComponentId -eq [string]::Empty)
{
throw [System.Management.Automation.ParameterBindingException] "Failed to provide valid NicAdapterDeviceId or NicAdapterComponentId"
}
$nicAdapterBasicPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"
Write-VerboseWriter("Probing started to detect NIC adapter registry path")
$nicAdapterRegKey = Invoke-RegistryGetValue -MachineName $ComputerName -Subkey $nicAdapterBasicPath -ReturnAfterOpenSubKey $true -CatchActionFunction $CatchActionFunction
$nicAdapterDeviceIDs = $nicAdapterRegKey.GetSubKeyNames() | Where-Object {$_.StartsWith("0")}
foreach($deviceID in $nicAdapterDeviceIDs)
{
$nicAdapterPnPCapabilitiesProbingKey = "{0}\{1}" -f $nicAdapterBasicPath, $deviceID
$netCfgInstanceId = Invoke-RegistryGetValue -MachineName $ComputerName -Subkey $nicAdapterPnPCapabilitiesProbingKey -GetValue "NetCfgInstanceId" -CatchActionFunction $CatchActionFunction
if ($netCfgInstanceId -eq $NicAdapterComponentId)
{
Write-VerboseWriter("Matching ComponentId found - now checking for PnPCapabilitiesValue")
$nicAdapterPnPCapabilitiesValue = Invoke-RegistryGetValue -MachineName $ComputerName -SubKey $nicAdapterPnPCapabilitiesProbingKey -GetValue "PnPCapabilities" -CatchActionFunction $CatchActionFunction
break
}
else
{
Write-VerboseWriter("No matching ComponentId found")
}
}
$obj = New-Object PSCustomObject
$sleepyNicDisabled = $false
if ($nicAdapterPnPCapabilitiesValue -eq 24 -or
$nicAdapterPnPCapabilitiesValue -eq 280)
{
$sleepyNicDisabled = $true
}
$obj | Add-Member -MemberType NoteProperty -Name "PnPCapabilities" -Value $nicAdapterPnPCapabilitiesValue
$obj | Add-Member -MemberType NoteProperty -Name "SleepyNicDisabled" -Value $sleepyNicDisabled
return $obj
}
Function Get-NetworkConfiguration {
[CmdletBinding()]
param(
[string]$ComputerName
)
try
{
$currentErrors = $Error.Count
$cimSession = New-CimSession -ComputerName $ComputerName -ErrorAction Stop
$networkIpConfiguration = Get-NetIPConfiguration -CimSession $CimSession -ErrorAction Stop | Where-Object {$_.NetAdapter.MediaConnectionState -eq "Connected"}
if ($CatchActionFunction -ne $null)
{
$index = 0
while ($index -lt ($Error.Count - $currentErrors))
{
& $CatchActionFunction $Error[$index]
$index++
}
}
return $networkIpConfiguration
}
catch
{
Write-VerboseWriter("Failed to run Get-NetIPConfiguration. Error {0}." -f $Error[0].Exception)
if ($CatchActionFunction -ne $null)
{
& $CatchActionFunction
}
throw
}
}
Function New-NICInformation {
param(
[array]$NetworkConfigurations,
[bool]$WmiObject
)
if($NetworkConfigurations -eq $null)
{
Write-VerboseWriter("NetworkConfigurations are null in New-NICInformation. Returning a null object.")
return $null
}
Function New-IpvAddresses {
$obj = New-Object PSCustomObject
$obj | Add-Member -MemberType NoteProperty -Name "Address" -Value ([string]::Empty)
$obj | Add-Member -MemberType NoteProperty -Name "Subnet" -Value ([string]::Empty)
$obj | Add-Member -MemberType NoteProperty -Name "DefaultGateway" -Value ([string]::Empty)
return $obj
}
if ($WmiObject)
{
$networkAdapterConfigurations = Get-WmiObjectHandler -ComputerName $ComputerName -Class "Win32_NetworkAdapterConfiguration" -Filter "IPEnabled = True" -CatchActionFunction $CatchActionFunction
}
[array]$nicObjects = @()
foreach($networkConfig in $NetworkConfigurations)
{
$dnsClient = $null
$rssEnabledValue = 2
$netAdapterRss = $null
if (!$WmiObject)
{
Write-VerboseWriter("Working on NIC: {0}" -f $networkConfig.InterfaceDescription)
$adapter = $networkConfig.NetAdapter
if($adapter.DriverFileName -ne "NdisImPlatform.sys")
{
$nicPnpCapabilitiesSetting = Get-NicPnpCapabilitiesSetting -NicAdapterComponentId $adapter.DeviceID
}
else
{
Write-VerboseWriter("Multiplexor adapter detected. Going to skip PnpCapabilities check")
$nicPnpCapabilitiesSetting = @{
PnPCapabilities = "MultiplexorNoPnP"
}
}
try
{
$dnsClient = $adapter | Get-DnsClient -ErrorAction Stop
Write-VerboseWriter("Got DNS Client information")
}
catch
{
Write-VerboseWriter("Failed to get the DNS Client information")
if ($CatchActionFunction -ne $null)
{
& $CatchActionFunction
}
}
try
{
$netAdapterRss = $adapter | Get-NetAdapterRss -ErrorAction Stop
Write-VerboseWriter("Got Net Adapter RSS information")
if ($netAdapterRss -ne $null)
{
[int]$rssEnabledValue = $netAdapterRss.Enabled
}
}
catch
{
Write-VerboseWriter("Failed to get RSS Information")
if ($CatchActionFunction -ne $null)
{
& $CatchActionFunction
}
}
}
else
{
Write-VerboseWriter("Working on NIC: {0}" -f $networkConfig.Description)
$adapter = $networkConfig
if($adapter.ServiceName -ne "NdisImPlatformMp")
{
$nicPnpCapabilitiesSetting = Get-NicPnpCapabilitiesSetting -NicAdapterComponentId $adapter.Guid
}
else
{
Write-VerboseWriter("Multiplexor adapter detected. Going to skip PnpCapabilities check")
$nicPnpCapabilitiesSetting = @{
PnPCapabilities = "MultiplexorNoPnP"
}
}
}
$nicInformationObj = New-Object PSCustomObject
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "WmiObject" -Value $WmiObject
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "Name" -Value ($adapter.Name)
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "LinkSpeed" -Value ((($adapter.Speed)/1000000).ToString() + " Mbps")
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "DriverDate" -Value [DateTime]::MaxValue
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "NICObject" -Value $networkConfig
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "NetAdapterRss" -Value $netAdapterRss
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "RssEnabledValue" -Value $rssEnabledValue
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "IPv6Enabled" -Value $false
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "Description" -Value $adapter.Description
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "DriverVersion" -Value [string]::Empty
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "MTUSize" -Value 0
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "PnPCapabilities" -Value ($nicPnpCapabilitiesSetting.PnPCapabilities)
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "SleepyNicDisabled" -Value ($nicPnpCapabilitiesSetting.SleepyNicDisabled)
if (!$WmiObject)
{
$nicInformationObj.MTUSize = $adapter.MtuSize
$nicInformationObj.DriverDate = $adapter.DriverDate
$nicInformationObj.DriverVersion = $adapter.DriverVersionString
$nicInformationObj.Description = $adapter.InterfaceDescription
foreach ($ipAddress in $networkConfig.AllIPAddresses.IPAddress)
{
if ($ipAddress.Contains(":"))
{
$nicInformationObj.IPv6Enabled = $true
}
}
$ipv4Address = @()
for ($i = 0; $i -lt $networkConfig.IPv4Address.Count; $i++)
{
$obj = New-IpvAddresses
if ($networkConfig.IPv4Address -ne $null -and
$i -lt $networkConfig.IPv4Address.Count)
{
$obj.Address = $networkConfig.IPv4Address[$i].IPAddress
$obj.Subnet = $networkConfig.IPv4Address[$i].PrefixLength
}
if ($networkConfig.IPv4DefaultGateway -ne $null -and
$i -lt $networkConfig.IPv4DefaultGateway.Count)
{
$obj.DefaultGateway = $networkConfig.IPv4DefaultGateway[$i].NextHop
}
$ipv4Address += $obj
}
$ipv6Address = @()
for ($i = 0; $i -lt $networkConfig.IPv6Address.Count; $i++)
{
$obj = New-IpvAddresses
if ($networkConfig.IPv6Address -ne $null -and
$i -lt $networkConfig.IPv6Address.Count)
{
$obj.Address = $networkConfig.IPv6Address[$i].IPAddress
$obj.Subnet = $networkConfig.IPv6Address[$i].PrefixLength
}
if ($networkConfig.IPv6DefaultGateway -ne $null -and
$i -lt $networkConfig.IPv6DefaultGateway.Count)
{
$obj.DefaultGateway = $networkConfig.IPv6DefaultGateway[$i].NextHop
}
$ipv6Address += $obj
}
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "IPv4Addresses" -Value $ipv4Address
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "Ipv6Addresses" -Value $ipv6Address
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "RegisteredInDns" -Value $dnsClient.RegisterThisConnectionsAddress
$nicInformationObj | Add-Member -MemberType NoteProperty -Name "DnsServer" -Value $networkConfig.DNSServer.ServerAddresses