forked from sacha81/XA-and-XD-HealthCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XA-and-XD-HealthCheck.ps1
1206 lines (1010 loc) · 50.9 KB
/
XA-and-XD-HealthCheck.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
#==============================================================================================
# Created on: 11.2014 Version: 1.1.0
# Created by: Sacha / sachathomet.ch & Contributers (see changelog)
# File name: XA-and-XD-HealthCheck.ps1
#
# Description: This script checks a Citrix XenDesktop and/or XenApp 7.x Farm
# It generates a HTML output File which will be sent as Email.
#
# Initial versions tested on XenApp/XenDesktop 7.6-7.11 and XenDesktop 5.6
# Newest version tested on XenApp/XenDesktop 7.9-7.11
#
# Prerequisite: Config file, a XenDesktop Controller with according privileges necessary
# Config file: In order for the script to work properly, it needs a configuration file.
# This has the same name as the script, with extension _Parameters.
# The script name can't contain any another point, even with a version.
# Example: Script = "XA and XD HealthCheck.ps1", Config = "XA and XD HealthCheck_Parameters.xml"
#
# Call by : Manual or by Scheduled Task, e.g. once a day
# Code History at the end of the file
#==============================================================================================
# Load only the snap-ins, which are used
if ((Get-PSSnapin "Citrix.Broker.Admin.*" -EA silentlycontinue) -eq $null) {
try { Add-PSSnapin Citrix.Broker.Admin.* -ErrorAction Stop }
catch { write-error "Error Get-PSSnapin Citrix.Broker.Admin.* Powershell snapin"; Return }
}
# Change the below variables to suit your environment
#==============================================================================================
# Import Variables from XML:
If (![string]::IsNullOrEmpty($hostinvocation)) {
[string]$Global:ScriptPath = [System.IO.Path]::GetDirectoryName([System.Windows.Forms.Application]::ExecutablePath)
[string]$Global:ScriptFile = [System.IO.Path]::GetFileName([System.Windows.Forms.Application]::ExecutablePath)
[string]$global:ScriptName = [System.IO.Path]::GetFileNameWithoutExtension([System.Windows.Forms.Application]::ExecutablePath)
} ElseIf ($Host.Version.Major -lt 3) {
[string]$Global:ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
[string]$Global:ScriptFile = Split-Path -Leaf $script:MyInvocation.MyCommand.Path
[string]$global:ScriptName = $ScriptFile.Split('.')[0].Trim()
} Else {
[string]$Global:ScriptPath = $PSScriptRoot
[string]$Global:ScriptFile = Split-Path -Leaf $PSCommandPath
[string]$global:ScriptName = $ScriptFile.Split('.')[0].Trim()
}
Set-StrictMode -Version Latest
# Import parameter file
$Global:ParameterFile = $ScriptName + "_Parameters.xml"
$Global:ParameterFilePath = $ScriptPath
[xml]$cfg = Get-Content ($ParameterFilePath + "\" + $ParameterFile) # Read content of XML file
# Import variables
Function New-XMLVariables {
# Create a variable reference to the XML file
$cfg.Settings.Variables.Variable | foreach {
# Set Variables contained in XML file
$VarValue = $_.Value
$CreateVariable = $True # Default value to create XML content as Variable
switch ($_.Type) {
# Format data types for each variable
'[string]' { $VarValue = [string]$VarValue } # Fixed-length string of Unicode characters
'[char]' { $VarValue = [char]$VarValue } # A Unicode 16-bit character
'[byte]' { $VarValue = [byte]$VarValue } # An 8-bit unsigned character
'[bool]' { If ($VarValue.ToLower() -eq 'false'){$VarValue = [bool]$False} ElseIf ($VarValue.ToLower() -eq 'true'){$VarValue = [bool]$True} } # An boolean True/False value
'[int]' { $VarValue = [int]$VarValue } # 32-bit signed integer
'[long]' { $VarValue = [long]$VarValue } # 64-bit signed integer
'[decimal]' { $VarValue = [decimal]$VarValue } # A 128-bit decimal value
'[single]' { $VarValue = [single]$VarValue } # Single-precision 32-bit floating point number
'[double]' { $VarValue = [double]$VarValue } # Double-precision 64-bit floating point number
'[DateTime]' { $VarValue = [DateTime]$VarValue } # Date and Time
'[Array]' { $VarValue = [Array]$VarValue.Split(',') } # Array
'[Command]' { $VarValue = Invoke-Expression $VarValue; $CreateVariable = $False } # Command
}
If ($CreateVariable) { New-Variable -Name $_.Name -Value $VarValue -Scope $_.Scope -Force }
}
}
New-XMLVariables
$PvsWriteMaxSize = $PvsWriteMaxSize * 1Gb
ForEach ($DeliveryController in $DeliveryControllers){
If ($DeliveryController -ieq "LocalHost"){
$DeliveryController = [System.Net.DNS]::GetHostByName('').HostName
}
If (Test-Connection $DeliveryController) {
$AdminAddress = $DeliveryController
break
}
}
$ReportDate = (Get-Date -UFormat "%A, %d. %B %Y %R")
$currentDir = Split-Path $MyInvocation.MyCommand.Path
$logfile = Join-Path $currentDir ("CTXXDHealthCheck.log")
$resultsHTM = Join-Path $currentDir ("CTXXDHealthCheck.htm")
#Header for Table "XD/XA Controllers" Get-BrokerController
$XDControllerFirstheaderName = "ControllerServer"
$XDControllerHeaderNames = "Ping", "State","DesktopsRegistered", "ActiveSiteServices", "CFreespace", "DFreespace", "AvgCPU", "MemUsg", "Uptime"
$XDControllerHeaderWidths = "2", "2", "2", "10", "4", "4", "4", "4", "4"
$XDControllerTableWidth= 1200
#Header for Table "MachineCatalogs" Get-BrokerCatalog
$CatalogHeaderName = "CatalogName"
$CatalogHeaderNames = "AssignedToUser", "AssignedToDG", "NotToUserAssigned","ProvisioningType", "AllocationType"
$CatalogWidths = "4", "8", "8", "8", "8"
$CatalogTablewidth = 900
#Header for Table "DeliveryGroups" Get-BrokerDesktopGroup
$AssigmentFirstheaderName = "DeliveryGroup"
$vAssigmentHeaderNames = "PublishedName","DesktopKind", "TotalDesktops","DesktopsAvailable","DesktopsUnregistered", "DesktopsInUse","DesktopsFree", "MaintenanceMode"
$vAssigmentHeaderWidths = "4", "4", "4", "4", "4", "4", "4", "2"
$Assigmenttablewidth = 900
#Header for Table "VDI Checks" Get-BrokerMachine
$VDIfirstheaderName = "Desktop-Name"
$VDIHeaderNames = "CatalogName","PowerState", "Ping", "MaintenanceMode", "Uptime", "RegistrationState","AssociatedUserNames", "VDAVersion", "WriteCacheType", "WriteCacheSize", "HostetOn"
$VDIHeaderWidths = "4", "4","4", "4", "4", "4", "4", "4", "4", "4", "4"
$VDItablewidth = 1200
#Header for Table "XenApp Checks" Get-BrokerMachine
$XenAppfirstheaderName = "XenApp-Server"
if ($ShowConnectedXenAppUsers -eq "1") {
$XenAppHeaderNames = "CatalogName", "DesktopGroupName", "Serverload", "Ping", "MaintMode","Uptime", "RegState", "Spooler", "CitrixPrint", "CFreespace", "DFreespace", "AvgCPU", "MemUsg", "ActiveSessions", "VDAVersion", "WriteCacheType", "WriteCacheSize", "ConnectedUsers" , "HostetOn"
$XenAppHeaderWidths = "4", "4", "4", "4", "4", "4", "4", "6", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4"
}
else {
$XenAppHeaderNames = "CatalogName", "DesktopGroupName", "Serverload", "Ping", "MaintMode","Uptime", "RegState", "Spooler", "CitrixPrint", "CFreespace", "DFreespace", "AvgCPU", "MemUsg", "ActiveSessions", "VDAVersion", "WriteCacheType", "WriteCacheSize", "HostetOn"
$XenAppHeaderWidths = "4", "4", "4", "4", "4", "4", "4", "6", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4"
}
$XenApptablewidth = 1200
#==============================================================================================
#log function
function LogMe() {
Param(
[parameter(Mandatory = $true, ValueFromPipeline = $true)] $logEntry,
[switch]$display,
[switch]$error,
[switch]$warning,
[switch]$progress
)
if ($error) { $logEntry = "[ERROR] $logEntry" ; Write-Host "$logEntry" -Foregroundcolor Red }
elseif ($warning) { Write-Warning "$logEntry" ; $logEntry = "[WARNING] $logEntry" }
elseif ($progress) { Write-Host "$logEntry" -Foregroundcolor Green }
elseif ($display) { Write-Host "$logEntry" }
#$logEntry = ((Get-Date -uformat "%D %T") + " - " + $logEntry)
$logEntry | Out-File $logFile -Append
}
#==============================================================================================
function Ping([string]$hostname, [int]$timeout = 200) {
$ping = new-object System.Net.NetworkInformation.Ping #creates a ping object
try { $result = $ping.send($hostname, $timeout).Status.ToString() }
catch { $result = "Failure" }
return $result
}
#==============================================================================================
# The function will check the processor counter and check for the CPU usage. Takes an average CPU usage for 5 seconds. It check the current CPU usage for 5 secs.
Function CheckCpuUsage()
{
param ($hostname)
Try { $CpuUsage=(get-counter -ComputerName $hostname -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 5 -ErrorAction Stop | select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average
$CpuUsage = [math]::round($CpuUsage, 1); return $CpuUsage
} Catch { "Error returned while checking the CPU usage. Perfmon Counters may be fault" | LogMe -error; return 101 }
}
#==============================================================================================
# The function check the memory usage and report the usage value in percentage
Function CheckMemoryUsage()
{
param ($hostname)
Try
{ $SystemInfo = (Get-WmiObject -computername $hostname -Class Win32_OperatingSystem -ErrorAction Stop | Select-Object TotalVisibleMemorySize, FreePhysicalMemory)
$TotalRAM = $SystemInfo.TotalVisibleMemorySize/1MB
$FreeRAM = $SystemInfo.FreePhysicalMemory/1MB
$UsedRAM = $TotalRAM - $FreeRAM
$RAMPercentUsed = ($UsedRAM / $TotalRAM) * 100
$RAMPercentUsed = [math]::round($RAMPercentUsed, 2);
return $RAMPercentUsed
} Catch { "Error returned while checking the Memory usage. Perfmon Counters may be fault" | LogMe -error; return 101 }
}
#==============================================================================================
# The function check the HardDrive usage and report the usage value in percentage and free space
Function CheckHardDiskUsage()
{
param ($hostname, $deviceID)
Try
{
$HardDisk = $null
$HardDisk = Get-WmiObject Win32_LogicalDisk -ComputerName $hostname -Filter "DeviceID='$deviceID'" -ErrorAction Stop | Select-Object Size,FreeSpace
if ($HardDisk -ne $null)
{
$DiskTotalSize = $HardDisk.Size
$DiskFreeSpace = $HardDisk.FreeSpace
$frSpace=[Math]::Round(($DiskFreeSpace/1073741824),2)
$PercentageDS = (($DiskFreeSpace / $DiskTotalSize ) * 100); $PercentageDS = [math]::round($PercentageDS, 2)
Add-Member -InputObject $HardDisk -MemberType NoteProperty -Name PercentageDS -Value $PercentageDS
Add-Member -InputObject $HardDisk -MemberType NoteProperty -Name frSpace -Value $frSpace
}
return $HardDisk
} Catch { "Error returned while checking the Hard Disk usage. Perfmon Counters may be fault" | LogMe -error; return $null }
}
#==============================================================================================
Function writeHtmlHeader
{
param($title, $fileName)
$date = $ReportDate
$head = @"
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>$title</title>
<STYLE TYPE="text/css">
<!--
td {
font-family: Tahoma;
font-size: 11px;
border-top: 1px solid #999999;
border-right: 1px solid #999999;
border-bottom: 1px solid #999999;
border-left: 1px solid #999999;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
overflow: hidden;
}
body {
margin-left: 5px;
margin-top: 5px;
margin-right: 0px;
margin-bottom: 10px;
table {
table-layout:fixed;
border: thin solid #000000;
}
-->
</style>
</head>
<body>
<table width='1200'>
<tr bgcolor='#CCCCCC'>
<td colspan='7' height='48' align='center' valign="middle">
<font face='tahoma' color='#003399' size='4'>
<strong>$title - $date</strong></font>
</td>
</tr>
</table>
"@
$head | Out-File $fileName
}
# ==============================================================================================
Function writeTableHeader
{
param($fileName, $firstheaderName, $headerNames, $headerWidths, $tablewidth)
$tableHeader = @"
<table width='$tablewidth'><tbody>
<tr bgcolor=#CCCCCC>
<td width='6%' align='center'><strong>$firstheaderName</strong></td>
"@
$i = 0
while ($i -lt $headerNames.count) {
$headerName = $headerNames[$i]
$headerWidth = $headerWidths[$i]
$tableHeader += "<td width='" + $headerWidth + "%' align='center'><strong>$headerName</strong></td>"
$i++
}
$tableHeader += "</tr>"
$tableHeader | Out-File $fileName -append
}
# ==============================================================================================
Function writeTableFooter
{
param($fileName)
"</table><br/>"| Out-File $fileName -append
}
#==============================================================================================
Function writeData
{
param($data, $fileName, $headerNames)
$tableEntry =""
$data.Keys | sort | foreach {
$tableEntry += "<tr>"
$computerName = $_
$tableEntry += ("<td bgcolor='#CCCCCC' align=center><font color='#003399'>$computerName</font></td>")
#$data.$_.Keys | foreach {
$headerNames | foreach {
#"$computerName : $_" | LogMe -display
try {
if ($data.$computerName.$_[0] -eq "SUCCESS") { $bgcolor = "#387C44"; $fontColor = "#FFFFFF" }
elseif ($data.$computerName.$_[0] -eq "WARNING") { $bgcolor = "#FF7700"; $fontColor = "#FFFFFF" }
elseif ($data.$computerName.$_[0] -eq "ERROR") { $bgcolor = "#FF0000"; $fontColor = "#FFFFFF" }
else { $bgcolor = "#CCCCCC"; $fontColor = "#003399" }
$testResult = $data.$computerName.$_[1]
}
catch {
$bgcolor = "#CCCCCC"; $fontColor = "#003399"
$testResult = ""
}
$tableEntry += ("<td bgcolor='" + $bgcolor + "' align=center><font color='" + $fontColor + "'>$testResult</font></td>")
}
$tableEntry += "</tr>"
}
$tableEntry | Out-File $fileName -append
}
# ==============================================================================================
Function writeHtmlFooter
{
param($fileName)
@"
</table>
<table width='1200'>
<tr bgcolor='#CCCCCC'>
<td colspan='7' height='25' align='left'>
<font face='courier' color='#000000' size='2'><strong>Uptime Threshold =</strong></font><font color='#003399' face='courier' size='2'> $maxUpTimeDays days</font>
</td>
</table>
</body>
</html>
"@ | Out-File $FileName -append
}
# ==============================================================================================
Function ToHumanReadable()
{
param($timespan)
If ($timespan.TotalHours -lt 1) {
return $timespan.Minutes + "minutes"
}
$sb = New-Object System.Text.StringBuilder
If ($timespan.Days -gt 0) {
[void]$sb.Append($timespan.Days)
[void]$sb.Append(" days")
[void]$sb.Append(", ")
}
If ($timespan.Hours -gt 0) {
[void]$sb.Append($timespan.Hours)
[void]$sb.Append(" hours")
}
If ($timespan.Minutes -gt 0) {
[void]$sb.Append(" and ")
[void]$sb.Append($timespan.Minutes)
[void]$sb.Append(" minutes")
}
return $sb.ToString()
}
#==============================================================================================
# == MAIN SCRIPT ==
#==============================================================================================
rm $logfile -force -EA SilentlyContinue
rm $resultsHTM -force -EA SilentlyContinue
"#### Begin with Citrix XenDestop / XenApp HealthCheck ######################################################################" | LogMe -display -progress
" " | LogMe -display -progress
# Log the loaded Citrix PS Snapins
(Get-PSSnapin "Citrix.*" -EA silentlycontinue).Name | ForEach {"PSSnapIn: " + $_ | LogMe -display -progress}
$controller = Get-BrokerController -AdminAddress $AdminAddress -DNSName $AdminAddress
$controllerversion = $controller.ControllerVersion
"Version: $controllerversion " | LogMe -display -progress
if ($controllerversion -lt 7 ) {
"XenDesktop/XenApp Version below 7.x ($controllerversion) - only DesktopCheck will be performed" | LogMe -display -progress
$ShowXenAppTable = 0
}
else { "XenDesktop/XenApp Version above 7.x ($controllerversion) - XenApp and DesktopCheck will be performed" | LogMe -display -progress }
#== Controller Check ============================================================================================
"Check Controllers #############################################################################" | LogMe -display -progress
" " | LogMe -display -progress
$ControllerResults = @{}
$Controllers = Get-BrokerController -AdminAddress $AdminAddress
foreach ($Controller in $Controllers) {
$tests = @{}
#Name of $Controller
$ControllerDNS = $Controller | %{ $_.DNSName }
"Controller: $ControllerDNS" | LogMe -display -progress
#Ping $Controller
$result = Ping $ControllerDNS 100
if ($result -ne "SUCCESS") { $tests.Ping = "Error", $result }
else { $tests.Ping = "SUCCESS", $result
#Now when Ping is ok also check this:
#State of this controller
$ControllerState = $Controller | %{ $_.State }
"State: $ControllerState" | LogMe -display -progress
if ($ControllerState -ne "Active") { $tests.State = "ERROR", $ControllerState }
else { $tests.State = "SUCCESS", $ControllerState }
#DesktopsRegistered on this controller
$ControllerDesktopsRegistered = $Controller | %{ $_.DesktopsRegistered }
"Registered: $ControllerDesktopsRegistered" | LogMe -display -progress
$tests.DesktopsRegistered = "NEUTRAL", $ControllerDesktopsRegistered
#ActiveSiteServices on this controller
$ActiveSiteServices = $Controller | %{ $_.ActiveSiteServices }
"ActiveSiteServices $ActiveSiteServices" | LogMe -display -progress
$tests.ActiveSiteServices = "NEUTRAL", $ActiveSiteServices
#==============================================================================================
# CHECK CPU AND MEMORY USAGE
#==============================================================================================
# Check the AvgCPU value for 5 seconds
$AvgCPUval = CheckCpuUsage ($ControllerDNS)
#$VDtests.LoadBalancingAlgorithm = "SUCCESS", "LB is set to BEST EFFORT"}
if( [int] $AvgCPUval -lt 75) { "CPU usage is normal [ $AvgCPUval % ]" | LogMe -display; $tests.AvgCPU = "SUCCESS", "$AvgCPUval %" }
elseif([int] $AvgCPUval -lt 85) { "CPU usage is medium [ $AvgCPUval % ]" | LogMe -warning; $tests.AvgCPU = "WARNING", "$AvgCPUval %" }
elseif([int] $AvgCPUval -lt 95) { "CPU usage is high [ $AvgCPUval % ]" | LogMe -error; $tests.AvgCPU = "ERROR", "$AvgCPUval %" }
elseif([int] $AvgCPUval -eq 101) { "CPU usage test failed" | LogMe -error; $tests.AvgCPU = "ERROR", "Err" }
else { "CPU usage is Critical [ $AvgCPUval % ]" | LogMe -error; $tests.AvgCPU = "ERROR", "$AvgCPUval %" }
$AvgCPUval = 0
# Check the Physical Memory usage
$UsedMemory = CheckMemoryUsage ($ControllerDNS)
if( $UsedMemory -lt 75) { "Memory usage is normal [ $UsedMemory % ]" | LogMe -display; $tests.MemUsg = "SUCCESS", "$UsedMemory %" }
elseif( [int] $UsedMemory -lt 85) { "Memory usage is medium [ $UsedMemory % ]" | LogMe -warning; $tests.MemUsg = "WARNING", "$UsedMemory %" }
elseif( [int] $UsedMemory -lt 95) { "Memory usage is high [ $UsedMemory % ]" | LogMe -error; $tests.MemUsg = "ERROR", "$UsedMemory %" }
elseif( [int] $UsedMemory -eq 101) { "Memory usage test failed" | LogMe -error; $tests.MemUsg = "ERROR", "Err" }
else { "Memory usage is Critical [ $UsedMemory % ]" | LogMe -error; $tests.MemUsg = "ERROR", "$UsedMemory %" }
$UsedMemory = 0
# Check C Disk Usage
$HardDisk = CheckHardDiskUsage -hostname $ControllerDNS -deviceID "C:"
if ($HardDisk -ne $null) {
$XAPercentageDS = $HardDisk.PercentageDS
$frSpace = $HardDisk.frSpace
If ( [int] $XAPercentageDS -gt 15) { "Disk Free is normal [ $XAPercentageDS % ]" | LogMe -display; $tests.CFreespace = "SUCCESS", "$frSpace GB" }
ElseIf ([int] $XAPercentageDS -eq 0) { "Disk Free test failed" | LogMe -error; $tests.CFreespace = "ERROR", "Err" }
ElseIf ([int] $XAPercentageDS -lt 5) { "Disk Free is Critical [ $XAPercentageDS % ]" | LogMe -error; $tests.CFreespace = "ERROR", "$frSpace GB" }
ElseIf ([int] $XAPercentageDS -lt 15) { "Disk Free is Low [ $XAPercentageDS % ]" | LogMe -warning; $tests.CFreespace = "WARNING", "$frSpace GB" }
Else { "Disk Free is Critical [ $XAPercentageDS % ]" | LogMe -error; $tests.CFreespace = "ERROR", "$frSpace GB" }
$XAPercentageDS = 0
$frSpace = 0
$HardDisk = $null
}
$tests.DFreespace = "NEUTRAL", "N/A"
if ( $ControllerHaveD -eq "1" ) {
# Check D Disk Usage on DeliveryController
$HardDiskd = CheckHardDiskUsage -hostname $ControllerDNS -deviceID "D:"
if ($HardDiskd -ne $null)
{
$XAPercentageDSd = $HardDiskd.PercentageDS
$frSpaced = $HardDiskd.frSpace
If ( [int] $XAPercentageDSd -gt 15) { "D: Disk Free is normal [ $XAPercentageDSd % ]" | LogMe -display; $tests.DFreespace = "SUCCESS", "$frSpaced GB" }
ElseIf ([int] $XAPercentageDSd -eq 0) { "D: Disk Free test failed" | LogMe -error; $tests.DFreespace = "ERROR", "Err" }
ElseIf ([int] $XAPercentageDSd -lt 5) { "D: Disk Free is Critical [ $XAPercentageDSd % ]" | LogMe -error; $tests.DFreespace = "ERROR", "$frSpaced GB" }
ElseIf ([int] $XAPercentageDSd -lt 15) { "D: Disk Free is Low [ $XAPercentageDSd % ]" | LogMe -warning; $tests.DFreespace = "WARNING", "$frSpaced GB" }
Else { "D: Disk Free is Critical [ $XAPercentageDSd % ]" | LogMe -error; $tests.DFreespace = "ERROR", "$frSpaced GB" }
$XAPercentageDSd = 0
$frSpaced = 0
$HardDiskd = $null
}
}
# Check uptime (Query over WMI)
$tests.WMI = "ERROR","Error"
try { $wmi=Get-WmiObject -class Win32_OperatingSystem -computer $ControllerDNS }
catch { $wmi = $null }
# Perform WMI related checks
if ($wmi -ne $null) {
$tests.WMI = "SUCCESS", "Success"
$LBTime=$wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date)
if ($uptime.days -lt $minUpTimeDaysDDC){
"reboot warning, last reboot: {0:D}" -f $LBTime | LogMe -display -warning
$tests.Uptime = "WARNING", (ToHumanReadable($uptime))
}
else { $tests.Uptime = "SUCCESS", (ToHumanReadable($uptime)) }
}
else { "WMI connection failed - check WMI for corruption" | LogMe -display -error }
}
" --- " | LogMe -display -progress
#Fill $tests into array
$ControllerResults.$ControllerDNS = $tests
}
#== Catalog Check ============================================================================================
"Check Catalog #################################################################################" | LogMe -display -progress
" " | LogMe -display -progress
$CatalogResults = @{}
$Catalogs = Get-BrokerCatalog -AdminAddress $AdminAddress
foreach ($Catalog in $Catalogs) {
$tests = @{}
#Name of MachineCatalog
$CatalogName = $Catalog | %{ $_.Name }
"Catalog: $CatalogName" | LogMe -display -progress
if ($ExcludedCatalogs -contains $CatalogName) {
"Excluded Catalog, skipping" | LogMe -display -progress
} else {
#CatalogAssignedCount
$CatalogAssignedCount = $Catalog | %{ $_.AssignedCount }
"Assigned: $CatalogAssignedCount" | LogMe -display -progress
$tests.AssignedToUser = "NEUTRAL", $CatalogAssignedCount
#CatalogUnassignedCount
$CatalogUnAssignedCount = $Catalog | %{ $_.UnassignedCount }
"Unassigned: $CatalogUnAssignedCount" | LogMe -display -progress
$tests.NotToUserAssigned = "NEUTRAL", $CatalogUnAssignedCount
# Assigned to DeliveryGroup
$CatalogUsedCountCount = $Catalog | %{ $_.UsedCount }
"Used: $CatalogUsedCountCount" | LogMe -display -progress
$tests.AssignedToDG = "NEUTRAL", $CatalogUsedCountCount
#ProvisioningType
$CatalogProvisioningType = $Catalog | %{ $_.ProvisioningType }
"ProvisioningType: $CatalogProvisioningType" | LogMe -display -progress
$tests.ProvisioningType = "NEUTRAL", $CatalogProvisioningType
#AllocationType
$CatalogAllocationType = $Catalog | %{ $_.AllocationType }
"AllocationType: $CatalogAllocationType" | LogMe -display -progress
$tests.AllocationType = "NEUTRAL", $CatalogAllocationType
"", ""
$CatalogResults.$CatalogName = $tests
}
" --- " | LogMe -display -progress
}
#== DeliveryGroups Check ============================================================================================
"Check Assigments #############################################################################" | LogMe -display -progress
" " | LogMe -display -progress
$AssigmentsResults = @{}
$Assigments = Get-BrokerDesktopGroup -AdminAddress $AdminAddress
foreach ($Assigment in $Assigments) {
$tests = @{}
#Name of DeliveryGroup
$DeliveryGroupName = $Assigment | %{ $_.Name }
"DeliveryGroup: $DeliveryGroupName" | LogMe -display -progress
if ($ExcludedCatalogs -contains $DeliveryGroupName) {
"Excluded Delivery Group, skipping" | LogMe -display -progress
} else {
#PublishedName
$AssigmentDesktopPublishedName = $Assigment | %{ $_.PublishedName }
"PublishedName: $AssigmentDesktopPublishedName" | LogMe -display -progress
$tests.PublishedName = "NEUTRAL", $AssigmentDesktopPublishedName
#DesktopsTotal
$TotalDesktops = $Assigment | %{ $_.TotalDesktops }
"DesktopsAvailable: $TotalDesktops" | LogMe -display -progress
$tests.TotalDesktops = "NEUTRAL", $TotalDesktops
#DesktopsAvailable
$AssigmentDesktopsAvailable = $Assigment | %{ $_.DesktopsAvailable }
"DesktopsAvailable: $AssigmentDesktopsAvailable" | LogMe -display -progress
$tests.DesktopsAvailable = "NEUTRAL", $AssigmentDesktopsAvailable
#DesktopKind
$AssigmentDesktopsKind = $Assigment | %{ $_.DesktopKind }
"DesktopKind: $AssigmentDesktopsKind" | LogMe -display -progress
$tests.DesktopKind = "NEUTRAL", $AssigmentDesktopsKind
#inMaintenanceMode
$AssigmentDesktopsinMaintenanceMode = $Assigment | %{ $_.inMaintenanceMode }
"inMaintenanceMode: $AssigmentDesktopsinMaintenanceMode" | LogMe -display -progress
if ($AssigmentDesktopsinMaintenanceMode) { $tests.MaintenanceMode = "WARNING", "ON" }
else { $tests.MaintenanceMode = "SUCCESS", "OFF" }
#DesktopsUnregistered
$AssigmentDesktopsUnregistered = $Assigment | %{ $_.DesktopsUnregistered }
"DesktopsUnregistered: $AssigmentDesktopsUnregistered" | LogMe -display -progress
if ($AssigmentDesktopsUnregistered -gt 0 ) {
"DesktopsUnregistered > 0 ! ($AssigmentDesktopsUnregistered)" | LogMe -display -progress
$tests.DesktopsUnregistered = "WARNING", $AssigmentDesktopsUnregistered
} else {
$tests.DesktopsUnregistered = "SUCCESS", $AssigmentDesktopsUnregistered
"DesktopsUnregistered <= 0 ! ($AssigmentDesktopsUnregistered)" | LogMe -display -progress
}
#DesktopsInUse
$AssigmentDesktopsInUse = $Assigment | %{ $_.DesktopsInUse }
"DesktopsInUse: $AssigmentDesktopsInUse" | LogMe -display -progress
$tests.DesktopsInUse = "NEUTRAL", $AssigmentDesktopsInUse
#DesktopFree
$AssigmentDesktopsFree = $AssigmentDesktopsAvailable - $AssigmentDesktopsInUse
"DesktopsFree: $AssigmentDesktopsFree" | LogMe -display -progress
if ($AssigmentDesktopsKind -eq "shared") {
if ($AssigmentDesktopsFree -gt 0 ) {
"DesktopsFree < 1 ! ($AssigmentDesktopsFree)" | LogMe -display -progress
$tests.DesktopsFree = "SUCCESS", $AssigmentDesktopsFree
} elseif ($AssigmentDesktopsFree -lt 0 ) {
"DesktopsFree < 1 ! ($AssigmentDesktopsFree)" | LogMe -display -progress
$tests.DesktopsFree = "SUCCESS", "N/A"
} else {
$tests.DesktopsFree = "WARNING", $AssigmentDesktopsFree
"DesktopsFree > 0 ! ($AssigmentDesktopsFree)" | LogMe -display -progress
}
} else {
$tests.DesktopsFree = "SUCCESS", "N/A"
}
#Fill $tests into array
$AssigmentsResults.$DeliveryGroupName = $tests
}
" --- " | LogMe -display -progress
}
# ======= Desktop Check ========
"Check virtual Desktops ####################################################################################" | LogMe -display -progress
" " | LogMe -display -progress
if($ShowDesktopTable -eq 1 ) {
$allResults = @{}
$machines = Get-BrokerMachine -MaxRecordCount $maxmachines -AdminAddress $AdminAddress| Where-Object {$_.SessionSupport -eq "SingleSession"}
# SessionSupport only availiable in XD 7.x - for this reason only distinguish in Version above 7 if Desktop or XenApp
if($controllerversion -lt 7 ) { $machines = Get-BrokerMachine -MaxRecordCount $maxmachines -AdminAddress $AdminAddress}
else { $machines = Get-BrokerMachine -MaxRecordCount $maxmachines -AdminAddress $AdminAddress| Where-Object {$_.SessionSupport -eq "SingleSession" } }
foreach($machine in $machines) {
$tests = @{}
$ErrorVDI = 0
# Column Name of Desktop
$machineDNS = $machine | %{ $_.DNSName }
"Machine: $machineDNS" | LogMe -display -progress
# Column CatalogName
$CatalogName = $machine | %{ $_.CatalogName }
"Catalog: $CatalogName" | LogMe -display -progress
$tests.CatalogName = "NEUTRAL", $CatalogName
# Column Powerstate
$Powered = $machine | %{ $_.PowerState }
"PowerState: $Powered" | LogMe -display -progress
$tests.PowerState = "NEUTRAL", $Powered
if ($Powered -eq "Off" -OR $Powered -eq "Unknown") {
$tests.PowerState = "NEUTRAL", $Powered
}
if ($Powered -eq "On") {
$tests.PowerState = "SUCCESS", $Powered
}
if ($Powered -eq "On" -OR $Powered -eq "Unknown") {
# Column Ping Desktop
$result = Ping $machineDNS 100
if ($result -eq "SUCCESS") {
$tests.Ping = "SUCCESS", $result
#==============================================================================================
# Column Uptime (Query over WMI - only if Ping successfull)
$tests.WMI = "ERROR","Error"
try { $wmi=Get-WmiObject -class Win32_OperatingSystem -computer $machineDNS }
catch { $wmi = $null }
# Perform WMI related checks
if ($wmi -ne $null) {
$tests.WMI = "SUCCESS", "Success"
$LBTime=$wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date)
if ($uptime.days -gt $maxUpTimeDays){
"reboot warning, last reboot: {0:D}" -f $LBTime | LogMe -display -warning
$tests.Uptime = "WARNING", $uptime.days
$ErrorVDI = $ErrorVDI + 1
}
else { $tests.Uptime = "SUCCESS", $uptime.days }
}
else { "WMI connection failed - check WMI for corruption" | LogMe -display -error }
}
else {
$tests.Ping = "Error", $result
$ErrorVDI = $ErrorVDI + 1
}
#END of Ping-Section
# Column RegistrationState
$RegistrationState = $machine | %{ $_.RegistrationState }
"State: $RegistrationState" | LogMe -display -progress
if ($RegistrationState -ne "Registered") {
$tests.RegistrationState = "ERROR", $RegistrationState
$ErrorVDI = $ErrorVDI + 1
}
else { $tests.RegistrationState = "SUCCESS", $RegistrationState }
}
# Column MaintenanceMode
$MaintenanceMode = $machine | %{ $_.InMaintenanceMode }
"MaintenanceMode: $MaintenanceMode" | LogMe -display -progress
if ($MaintenanceMode) { $tests.MaintenanceMode = "WARNING", "ON"
$ErrorVDI = $ErrorVDI + 1
}
else { $tests.MaintenanceMode = "SUCCESS", "OFF" }
# Column HostedOn
$HostedOn = $machine | %{ $_.HostingServerName }
"HostedOn: $HostedOn" | LogMe -display -progress
$tests.HostedOn = "NEUTRAL", $HostedOn
# Column VDAVersion AgentVersion
$VDAVersion = $machine | %{ $_.AgentVersion }
"VDAVersion: $VDAVersion" | LogMe -display -progress
$tests.VDAVersion = "NEUTRAL", $VDAVersion
# Column AssociatedUserNames
$AssociatedUserNames = $machine | %{ $_.AssociatedUserNames }
"Assigned to $AssociatedUserNames" | LogMe -display -progress
$tests.AssociatedUserNames = "NEUTRAL", $AssociatedUserNames
" --- " | LogMe -display -progress
# Fill $tests into array if error occured OR $ShowOnlyErrorVDI = 0
# Check to see if the server is in an excluded folder path
if ($ExcludedCatalogs -contains $CatalogName) {
"$machineDNS in excluded folder - skipping" | LogMe -display -progress
}
else {
# Check if error exists on this vdi
if ($ShowOnlyErrorVDI -eq 0 ) { $allResults.$machineDNS = $tests }
else {
if ($ErrorVDI -gt 0) { $allResults.$machineDNS = $tests }
else { "$machineDNS is ok, no output into HTML-File" | LogMe -display -progress }
}
}
}
}
else { "Desktop Check skipped because ShowDesktopTable = 0 " | LogMe -display -progress }
# ======= XenApp Check ========
"Check XenApp Servers ####################################################################################" | LogMe -display -progress
" " | LogMe -display -progress
# Check XenApp only if $ShowXenAppTable is 1
if($ShowXenAppTable -eq 1 ) {
$allXenAppResults = @{}
$XAmachines = Get-BrokerMachine -MaxRecordCount $maxmachines -AdminAddress $AdminAddress | Where-Object {$_.SessionSupport -eq "MultiSession"}
foreach ($XAmachine in $XAmachines) {
$tests = @{}
# Column Name of Machine
$machineDNS = $XAmachine | %{ $_.DNSName }
"Machine: $machineDNS" | LogMe -display -progress
# Column CatalogNameName
$CatalogName = $XAmachine | %{ $_.CatalogName }
"Catalog: $CatalogName" | LogMe -display -progress
$tests.CatalogName = "NEUTRAL", $CatalogName
# Ping Machine
$result = Ping $machineDNS 100
if ($result -eq "SUCCESS") {
$tests.Ping = "SUCCESS", $result
#==============================================================================================
# Column Uptime (Query over WMI - only if Ping successfull)
$tests.WMI = "ERROR","Error"
try { $wmi = Get-WmiObject -class Win32_OperatingSystem -computer $machineDNS }
catch { $wmi = $null }
# Column Perform WMI related checks
if ($wmi -ne $null) {
$tests.WMI = "SUCCESS", "Success"
$LBTime=$wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$uptime=New-TimeSpan $LBTime $(get-date)
if ($uptime.days -gt $maxUpTimeDays) {
"reboot warning, last reboot: {0:D}" -f $LBTime | LogMe -display -warning
$tests.Uptime = "WARNING", $uptime.days
}
else { $tests.Uptime = "SUCCESS", $uptime.days }
}
else { "WMI connection failed - check WMI for corruption" | LogMe -display -error }
#----
# Column WriteCacheSize (only if Ping is successful)
################ PVS SECTION ###############
if (test-path \\$machineDNS\c$\Personality.ini) {
# Test if PVS cache is of type "device's hard drive"
$PvsWriteCacheUNC = Join-Path "\\$machineDNS" ($PvsWriteCacheDrive+"$"+"\.vdiskcache")
$CacheDiskOnHD = Test-Path $PvsWriteCacheUNC
if ($CacheDiskOnHD -eq $True) {
$CacheDiskExists = $True
$CachePVSType = "Device HD"
} else {
# Test if PVS cache is of type "device RAM with overflow to hard drive"
$PvsWriteCacheUNC = Join-Path "\\$machineDNS" ($PvsWriteCacheDrive+"$"+"\vdiskdif.vhdx")
$CacheDiskRAMwithOverflow = Test-Path $PvsWriteCacheUNC
if ($CacheDiskRAMwithOverflow -eq $True) {
$CacheDiskExists = $True
$CachePVSType = "Device RAM with overflow to disk"
} else {
$CacheDiskExists = $False
$CachePVSType = ""
}
}
if ($CacheDiskExists -eq $True) {
$CacheDisk = [long] ((get-childitem $PvsWriteCacheUNC -force).length)
$CacheDiskGB = "{0:n2}GB" -f($CacheDisk / 1GB)
"PVS Cache file size: {0:n2}GB" -f($CacheDisk / 1GB) | LogMe
#"PVS Cache max size: {0:n2}GB" -f($PvsWriteMaxSize / 1GB) | LogMe -display
$tests.WriteCacheType = "NEUTRAL", $CachePVSType
if ($CacheDisk -lt ($PvsWriteMaxSize * 0.5)) {
"WriteCache file size is low" | LogMe
$tests.WriteCacheSize = "SUCCESS", $CacheDiskGB
}
elseif ($CacheDisk -lt ($PvsWriteMaxSize * 0.8)) {
"WriteCache file size moderate" | LogMe -display -warning
$tests.WriteCacheSize = "WARNING", $CacheDiskGB
}
else {
"WriteCache file size is high" | LogMe -display -error
$tests.WriteCacheSize = "ERROR", $CacheDiskGB
}
}
$Cachedisk = 0
}
else { $tests.WriteCacheSize = "SUCCESS", "N/A" }
############## END PVS SECTION #############
# Check services
$services = Get-Service -Computer $machineDNS
if (($services | ? {$_.Name -eq "Spooler"}).Status -Match "Running") {
"SPOOLER service running..." | LogMe
$tests.Spooler = "SUCCESS","Success"
}
else {
"SPOOLER service stopped" | LogMe -display -error
$tests.Spooler = "ERROR","Error"
}
if (($services | ? {$_.Name -eq "cpsvc"}).Status -Match "Running") {
"Citrix Print Manager service running..." | LogMe
$tests.CitrixPrint = "SUCCESS","Success"
}
else {
"Citrix Print Manager service stopped" | LogMe -display -error
$tests.CitrixPrint = "ERROR","Error"
}
}
else { $tests.Ping = "Error", $result }
#END of Ping-Section
# Column Serverload
$Serverload = $XAmachine | %{ $_.LoadIndex }
"Serverload: $Serverload" | LogMe -display -progress
if ($Serverload -ge $loadIndexError) { $tests.Serverload = "ERROR", $Serverload }
elseif ($Serverload -ge $loadIndexWarning) { $tests.Serverload = "WARNING", $Serverload }
else { $tests.Serverload = "SUCCESS", $Serverload }
# Column MaintMode
$MaintMode = $XAmachine | %{ $_.InMaintenanceMode }
"MaintenanceMode: $MaintMode" | LogMe -display -progress
if ($MaintMode) { $tests.MaintMode = "WARNING", "ON"
$ErrorVDI = $ErrorVDI + 1
}
else { $tests.MaintMode = "SUCCESS", "OFF" }
# Column RegState
$RegState = $XAmachine | %{ $_.RegistrationState }
"State: $RegState" | LogMe -display -progress
if ($RegState -ne "Registered") { $tests.RegState = "ERROR", $RegState }
else { $tests.RegState = "SUCCESS", $RegState }
# Column VDAVersion AgentVersion
$VDAVersion = $XAmachine | %{ $_.AgentVersion }
"VDAVersion: $VDAVersion" | LogMe -display -progress
$tests.VDAVersion = "NEUTRAL", $VDAVersion
# Column HostedOn
$HostedOn = $XAmachine | %{ $_.HostingServerName }
"HostedOn: $HostedOn" | LogMe -display -progress
$tests.HostedOn = "NEUTRAL", $HostedOn
# Column ActiveSessions
$ActiveSessions = $XAmachine | %{ $_.SessionCount }
"Active Sessions: $ActiveSessions" | LogMe -display -progress
$tests.ActiveSessions = "NEUTRAL", $ActiveSessions
# Column ConnectedUsers
$ConnectedUsers = $XAmachine | %{ $_.AssociatedUserNames }
"Connected users: $ConnectedUsers" | LogMe -display -progress
$tests.ConnectedUsers = "NEUTRAL", $ConnectedUsers
# Column DesktopGroupName
$DesktopGroupName = $XAmachine | %{ $_.DesktopGroupName }
"DesktopGroupName: $DesktopGroupName" | LogMe -display -progress
$tests.DesktopGroupName = "NEUTRAL", $DesktopGroupName
#==============================================================================================
# CHECK CPU AND MEMORY USAGE
#==============================================================================================
# Check the AvgCPU value for 5 seconds
$XAAvgCPUval = CheckCpuUsage ($machineDNS)
#$VDtests.LoadBalancingAlgorithm = "SUCCESS", "LB is set to BEST EFFORT"}
if( [int] $XAAvgCPUval -lt 75) { "CPU usage is normal [ $XAAvgCPUval % ]" | LogMe -display; $tests.AvgCPU = "SUCCESS", "$XAAvgCPUval %" }
elseif([int] $XAAvgCPUval -lt 85) { "CPU usage is medium [ $XAAvgCPUval % ]" | LogMe -warning; $tests.AvgCPU = "WARNING", "$XAAvgCPUval %" }
elseif([int] $XAAvgCPUval -lt 95) { "CPU usage is high [ $XAAvgCPUval % ]" | LogMe -error; $tests.AvgCPU = "ERROR", "$XAAvgCPUval %" }
elseif([int] $XAAvgCPUval -eq 101) { "CPU usage test failed" | LogMe -error; $tests.AvgCPU = "ERROR", "Err" }
else { "CPU usage is Critical [ $XAAvgCPUval % ]" | LogMe -error; $tests.AvgCPU = "ERROR", "$XAAvgCPUval %" }
$XAAvgCPUval = 0
# Check the Physical Memory usage
[int] $XAUsedMemory = CheckMemoryUsage ($machineDNS)
if( [int] $XAUsedMemory -lt 75) { "Memory usage is normal [ $XAUsedMemory % ]" | LogMe -display; $tests.MemUsg = "SUCCESS", "$XAUsedMemory %" }
elseif( [int] $XAUsedMemory -lt 85) { "Memory usage is medium [ $XAUsedMemory % ]" | LogMe -warning; $tests.MemUsg = "WARNING", "$XAUsedMemory %" }
elseif( [int] $XAUsedMemory -lt 95) { "Memory usage is high [ $XAUsedMemory % ]" | LogMe -error; $tests.MemUsg = "ERROR", "$XAUsedMemory %" }
elseif( [int] $XAUsedMemory -eq 101) { "Memory usage test failed" | LogMe -error; $tests.MemUsg = "ERROR", "Err" }
else { "Memory usage is Critical [ $XAUsedMemory % ]" | LogMe -error; $tests.MemUsg = "ERROR", "$XAUsedMemory %" }
$XAUsedMemory = 0
# Check C Disk Usage
$HardDisk = CheckHardDiskUsage -hostname $machineDNS -deviceID "C:"
if ($HardDisk -ne $null) {
$XAPercentageDS = $HardDisk.PercentageDS
$frSpace = $HardDisk.frSpace
If ( [int] $XAPercentageDS -gt 15) { "Disk Free is normal [ $XAPercentageDS % ]" | LogMe -display; $tests.CFreespace = "SUCCESS", "$frSpace GB" }
ElseIf ([int] $XAPercentageDS -eq 0) { "Disk Free test failed" | LogMe -error; $tests.CFreespace = "ERROR", "Err" }
ElseIf ([int] $XAPercentageDS -lt 5) { "Disk Free is Critical [ $XAPercentageDS % ]" | LogMe -error; $tests.CFreespace = "ERROR", "$frSpace GB" }
ElseIf ([int] $XAPercentageDS -lt 15) { "Disk Free is Low [ $XAPercentageDS % ]" | LogMe -warning; $tests.CFreespace = "WARNING", "$frSpace GB" }
Else { "Disk Free is Critical [ $XAPercentageDS % ]" | LogMe -error; $tests.CFreespace = "ERROR", "$frSpace GB" }
$XAPercentageDS = 0
$frSpace = 0
$HardDisk = $null
}