-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathGet-HyperVReport.ps1
3467 lines (3011 loc) · 159 KB
/
Get-HyperVReport.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
<#
.SYNOPSIS
Get-HyperVReport.ps1 (aka Hyper-V Reporting Script) can be used to report Hyper-V Cluster or Standalone environments.
Highlights:
o Creates a plain but detailed and user-friendly HTML report which is compatible with all modern browsers.
o Has an Overview section which shows momentary cluster resource usage.
o Storage Overcommitment (see details below)
o Shows alerts in the report for certain situations (utilizations, vm checkpoints, replication status, etc.)
o Provides more detailed information via tooltips in the HTML report. (cells with asteriks and highlighted)
o Includes a mode that reports only alerts in the Hyper-V environment. (aka HighlightsOnly mode)
o Collects information by using standard Hyper-V and Clustering PowerShell cmdlets and custom WMI queries.
o Checks and installs required runtime environment prerequisites like Hyper-V and Clustering Powershells.
o Can be used directly from command-line or as a scheduled Windows task.
o Supports report delivery via e-mail with advanced options. (authentication, TLS/SSL, multiple recipients)
o Advanced error handling and logging. (Console messages and log file)
Version History:
[x] Version 1.5 - 05.March.2015
Requirements:
o Hyper-V Targets (Clustered or Standalone)
* Active Directory domain membership
* Supported Operating Systems
- Windows Server 2012
- Windows Server 2012 R2
- Hyper-V Server 2012
- Hyper-V Server 2012 R2
o Script Runtime Operating System (directly on a Hyper-V target or remote Windows operating system)
* Same or trusted Active Directory domain membership with Hyper-V target
* Supported Operating Systems
- Windows Server 2012
- Windows Server 2012 R2
- Windows 8
- Windows 8.1
* Windows PowerShell 3.0 or 4.0 (installed by default on supported server operating systems)
* Sets the Windows PowerShell execution policy to RemoteSigned or Unrestricted
* Hyper-V PowerShell (if not, automatically installed by the Get-HyperVReport.ps1 for server oses)
* Failover Clustering PowerShell (if not, automatically installed by the Get-HyperVReport.ps1 for server oses)
* The script requires administrative privileges on the target Hyper-V server(s)
.DESCRIPTION
It can be difficult to monitor and assess resources in large Hyper-V environments. This script helps you to understand virtualization inventory, capacity and general resource availability in your Hyper-V environment.
Report details:
1) Cluster Overview (Applicable on clusters only):
o Pyhsical Resources
* Node
* Processor
* Memory
* Storage
o Virtual Resources
* vMachine
* vProcessor
* vMemory
* vStorage
2) Hyper-V Host (Clustered or Standalone):
o Hostname
* Computer Manufacturer, Model
o Operating System Version
o State
o Uptime
o Domain Name
o Total and Running VM Count
* Detailed as Clustered and Non-clustered
o Processor Count
* Logical processor count
* Physical processor socket count
* Processor Manufacturer, Model, Ghz
* Hyper-Threading state for Intel processor (shown as tooltip)
* Virtual Processors per Logical Processor ratio
o Used Physical RAM
o Free Physical RAM
o Total Physical RAM
3) Disk/Volume (Clustered or Standalone):
o Name
* Volume Name (Local Volume, Clustered Volume, Cluster Shared Volume)
* Volume label or CSV path (shown as tooltip)
* Disk name (Physical Disk, Clustered Disk)
* Total/Allocated/Unallocated physical disk size (shown as tooltip)
o Disk/Volume State
o Usage (Logical Partition, Cluster Volume, Cluster Shared Volume, Quorum, System Volume, Pass-through, Unassigned)
o Owner
o Physical Disk Bus Type
o Volume File System
o Active VHD (Storage Overcommitment)
o Used Size
o Free Size
o Total Size
4) Virtual Machine
o Name
* VM name
* Configuration XML path (shown as tooltip)
* Generation
* Version
o State
o Uptime
o Owner
* Owner hostname
o Virtual Processor
* Count
o Virtual RAM
* Startup
* Minimum (if dynamic memory enabled)
* Maximum (if dynamic memory enabled)
* Assigned
o Integration Services
* State like UpToDate, UpdateRequired, MayBeRequired, NotDetected
* Version number (shown as tooltip)
o Checkpoint
* Checkpoint state
* Checkpoint count (if exists, shown as tooltip)
* Checkpoint chain (if exists)
o Replica
* Replication State and Health
* Primary, Replica and Extended modes
* Replica Server or Primary Server (shown as tooltip)
* Replication Frequency (shown as tooltip)
* Last Replication Time (shown as tooltip)
o Disk
* VHD Name
* VHD File Path (shown as tooltip)
* Current VHD file size
* Maximum VHD disk size
* VHD Type
* Controller Type
* VHD fragmentation percent
* Including pass-through disks (if exists)
* Including differencing virtual disk chain (if exists)
* Can detects missing VHD files (if exists)
o Network Adapter
* Device type
* Connection status
* Virtual switch name
* IP address
* VLAN ID
* Advanced - MAC Address, MAC Type, DHCP Guard, Raouter Guard, Port Mirroring, Protected Network
o Can detects missing VHD files
o Can detects clustered VM configuration resource problems like offline
o Can detects clustered VM failed state
.PARAMETER Cluster
A single Hyper-V Cluster name.
.PARAMETER VMHost
A single standalone Hyper-V Host name or an array of standalone Hyper-V Host names.
.PARAMETER HighlightsOnly
A filtering mode only allows the reporting of highlighted events and alerts.
.PARAMETER ReportFilePath
HTML report file path. Script working directory is the default value.
.PARAMETER ReportFileNamePrefix
HTML report file name prefix. The default value is "HyperVReport"
.PARAMETER SendMail
Send e-mail option ($true/$false). The default value is "$fale".
.PARAMETER SMTPServer
Mail server address.
.PARAMETER SMTPPort
Mail server port. The default value is "25".
.PARAMETER MailTo
A single mail recipient or an array of mail recipients.
.PARAMETER MailFrom
Mail sender address.
.PARAMETER MailFromPassword
Mail sender password for SMTP authentication.
.PARAMETER SMTPServerTLSorSSL
SMTP TLS/SSL option ($true/$false). The default value is "$fale".
.PARAMETER ReportFileNameTimeStamp
Adds Timestamp to HTML report file name (The default is $true). If you set it to $false then html report’s filename will not have date and time value and it will always has the same filename.
.EXAMPLE
Creates a Hyper-V Cluster report in the working directory.
.\Get-HyperVReport.ps1 -Cluster Hvcluster1
.EXAMPLE
Creates a Hyper-V Cluster report that shown only highlighted events and alerts in the working directory.
.\Get-HyperVReport.ps1 -Cluster Hvcluster1 -HighlightsOnly $true
.EXAMPLE
Creates one or more standalone Hyper-V Host(s) report in the working directory.
.\Get-HyperVReport.ps1 -VMHost Host1,Host2,Host3
.EXAMPLE
Creates a Hyper-V Cluster report with custom file name prefix and saves is to the specified folder.
.\Get-HyperVReport.ps1 -Cluster Hvcluster1 -ReportFileNamePrefix HvReport -ReportFilePath c:\tools
.EXAMPLE
Creates a Hyper-V Cluster report and sends it to multiple recipients as attachment without smtp authentication.
.\Get-HyperVReport.ps1 -Cluster Hvcluster1 -SendMail $true -SMTPServer 10.29.0.50 -MailFrom [email protected] -MailTo [email protected],[email protected]
.EXAMPLE
Creates a Hyper-V Cluster report and sends it to multiple recipients as attachment with smtp authentication and TLS/SSL communication. -SMTPServerTLSorSSL is optional and used if forced by the smtp server.
.\Get-HyperVReport.ps1 -Cluster Hvcluster1 -SendMail $true -SMTPServer 10.29.0.50 -MailFrom [email protected] -MailFromPassword P@ssw0rd -SMTPServerTLSorSSL $true -MailTo [email protected],[email protected]
.INPUTS
None
.OUTPUTS
None
#>
#region Script Parameters
# -----------------------
[CmdletBinding(SupportsShouldProcess=$True)]
Param (
[parameter(
Mandatory=$false,
HelpMessage='Hyper-V Cluster name (like HvCluster1 or hvcluster1.domain.corp')]
[string]$Cluster,
[parameter(
Mandatory=$false,
HelpMessage='Standalone Hyper-V Host name(s) (like Host1, Host2, Host3)')]
[array]$VMHost,
[parameter(
Mandatory=$false,
HelpMessage='Reports that shown only highlighted events and alerts')]
[bool]$HighlightsOnly = $false,
[parameter(
Mandatory=$false,
HelpMessage='Disk path for HTML reporting file')]
[string]$ReportFilePath = (Get-Location).path,
[parameter(
Mandatory=$false,
HelpMessage='Adds a prefix to the HTML report file name (The default nameprefix is HyperVReport)')]
[string]$ReportFileNamePrefix = "HyperVReport",
[parameter(
Mandatory=$false,
HelpMessage='Adds Timestamp to HTML report file name (The default is $true)')]
[bool]$ReportFileNameTimeStamp = $false,
[parameter(
Mandatory=$false,
HelpMessage='Activates the e-mail sending feature ($true/$false). The default value is "$false"')]
[bool]$SendMail = $false,
[parameter(
Mandatory=$false,
HelpMessage='SMTP Server Address (Like IP address, hostname or FQDN)')]
[string]$SMTPServer,
[parameter(
Mandatory=$false,
HelpMessage='SMTP Server port number (Default 25)')]
[int]$SMTPPort = "25",
[parameter(
Mandatory=$false,
HelpMessage='Recipient e-mail address')]
[array]$MailTo,
[parameter(
Mandatory=$false,
HelpMessage='Sender e-mail address')]
[string]$MailFrom,
[parameter(
Mandatory=$false,
HelpMessage='Sender e-mail address password for SMTP authentication (If needed)')]
[string]$MailFromPassword,
[parameter(
Mandatory=$false,
HelpMessage='SMTP TLS/SSL option ($true/$false). The default value is "$false"')]
[bool]$SMTPServerTLSorSSL = $false
)
#endregion Script Parameters
#region Functions
#----------------
# Get WMI data
function sGet-Wmi {
param (
[Parameter(Mandatory = $true)]
[string]$ComputerName,
[Parameter(Mandatory = $true)]
[string]$Namespace,
[Parameter(Mandatory = $true)]
[string]$Class,
[Parameter(Mandatory = $false)]
$Property,
[Parameter(Mandatory = $false)]
$Filter,
[Parameter(Mandatory = $false)]
[switch]$AI
)
# Base string
$wmiCommand = "gwmi -ComputerName $ComputerName -Namespace $Namespace -Class $Class -ErrorAction Stop"
# If available, add Filter parameter
if ($Filter)
{
# $Filter = ($Filter -join ',').ToString()
$Filter = [char]34 + $Filter + [char]34
$wmiCommand += " -Filter $Filter"
}
# If available, add Property parameter
if ($Property)
{
$Property = ($Property -join ',').ToString()
$wmiCommand += " -Property $Property"
}
# If available, Authentication and Impersonation
if ($AI)
{
$wmiCommand += " -Authentication PacketPrivacy -Impersonation Impersonate"
}
# Try to connect
$ResultCode = "1"
Try
{
# $wmiCommand
$wmiResult = iex $wmiCommand
}
Catch
{
$wmiResult = $_.Exception.Message
$ResultCode = "0"
}
# If wmiResult is null
if ($wmiResult -eq $null)
{
$wmiResult = "Result is null"
$ResultCode = "2"
}
Return $wmiResult, $ResultCode
}
# Write Log
Function sPrint {
param(
[byte]$Type=1,
[string]$Message,
[bool]$WriteToLogFile
)
$TimeStamp = Get-Date -Format "dd.MMM.yyyy HH:mm:ss"
$Time = Get-Date -Format "HH:mm:ss"
if ($Type -eq 1)
{
Write-Host "[INFO] - $Time - $Message" -ForegroundColor Green
if (($WriteToLogFile) -and ($Logging))
{
Add-Content -Path $LogFile -Value "[INFO] - $TimeStamp - $Message"
}
}
elseif ($Type -eq 2)
{
Write-Host "[WARNING] - $Time - $Message" -ForegroundColor Yellow
if (($WriteToLogFile) -and ($Logging))
{
Add-Content -Path $LogFile -Value "[WARNING] - $TimeStamp - $Message"
}
}
elseif ($Type -eq 5)
{
if (($WriteToLogFile) -and ($Logging))
{
Add-Content -Path $LogFile -Value "[DEBUG] - $TimeStamp - $Message"
}
}
elseif ($Type -eq 6)
{
if (($WriteToLogFile) -and ($Logging))
{
Add-Content -Path $LogFile -Value ""
}
}
elseif ($Type -eq 0)
{
Write-Host "[ERROR] - $Time - $Message" -ForegroundColor Red
if (($WriteToLogFile) -and ($Logging))
{
Add-Content -Path $LogFile -Value "[ERROR] - $TimeStamp - $Message"
}
}
else
{
Write-Host "[UNKNOWN] - $Time - $Message" -ForegroundColor Gray
if (($WriteToLogFile) -and ($Logging))
{
Add-Content -Path $LogFile -Value "[UNKNOWN] - $TimeStamp - $Message"
}
}
}
# Convert Volume Size to KB/MB/GB/TB
Function sConvert-Size {
param (
# Disk or Volume Space
[Parameter(Mandatory = $false)]
$DiskVolumeSpace,
# Disk or Volume Space Input Unit
[Parameter(Mandatory = $true)]
[string]$DiskVolumeSpaceUnit
)
if ($DiskVolumeSpaceUnit -eq "byte") # byte input
{
if (($DiskVolumeSpace -ge "1024") -and ($DiskVolumeSpace -lt "1048576"))
{
$DiskVolumeSpace = [math]::round(($DiskVolumeSpace/1024))
$DiskVolumeSpaceUnit = "KB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1048576") -and ($DiskVolumeSpace -lt "1073741824"))
{
$DiskVolumeSpace = [math]::round(($DiskVolumeSpace/1024/1024))
$DiskVolumeSpaceUnit = "MB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1073741824") -and ($DiskVolumeSpace -lt "1099511627776"))
{
$DiskVolumeSpace = "{0:N1}" -f ($DiskVolumeSpace/1024/1024/1024)
$DiskVolumeSpaceUnit = "GB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1099511627776") -and ($DiskVolumeSpace -lt "1125899906842624"))
{
$DiskVolumeSpace = "{0:N2}" -f ($DiskVolumeSpace/1024/1024/1024/1024)
$DiskVolumeSpaceUnit = "TB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif ($DiskVolumeSpace -eq $null)
{
$DiskVolumeSpace = "N/A"
$DiskVolumeSpaceUnit = "-"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
else
{
$DiskVolumeSpace = $DiskVolumeSpace
$DiskVolumeSpaceUnit = "Byte"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
}
elseif ($DiskVolumeSpaceUnit -eq "kb") # kb input
{
if (($DiskVolumeSpace -ge "1") -and ($DiskVolumeSpace -lt "1024"))
{
$DiskVolumeSpace = $DiskVolumeSpace
$DiskVolumeSpaceUnit = "KB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1024") -and ($DiskVolumeSpace -lt "1048576"))
{
$DiskVolumeSpace = ($DiskVolumeSpace/1024)
$DiskVolumeSpaceUnit = "MB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1048576") -and ($DiskVolumeSpace -lt "1073741824"))
{
$DiskVolumeSpace = "{0:N1}" -f ($DiskVolumeSpace/1024/1024)
$DiskVolumeSpaceUnit = "GB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1073741824") -and ($DiskVolumeSpace -lt "1099511627776"))
{
$DiskVolumeSpace = "{0:N2}" -f ($DiskVolumeSpace/1024/1024/1024)
$DiskVolumeSpaceUnit = "TB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif ($DiskVolumeSpace -eq $null)
{
$DiskVolumeSpace = "N/A"
$DiskVolumeSpaceUnit = "-"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
else
{
$DiskVolumeSpace = $DiskVolumeSpace
$DiskVolumeSpaceUnit = "KB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
}
elseif ($DiskVolumeSpaceUnit -eq "mb") # mb input
{
if (($DiskVolumeSpace -ge "1") -and ($DiskVolumeSpace -lt "1024"))
{
$DiskVolumeSpace = $DiskVolumeSpace
$DiskVolumeSpaceUnit = "MB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1024") -and ($DiskVolumeSpace -lt "1048576"))
{
$DiskVolumeSpace = "{0:N1}" -f ($DiskVolumeSpace/1024)
$DiskVolumeSpaceUnit = "GB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif (($DiskVolumeSpace -ge "1048576") -and ($DiskVolumeSpace -lt "1073741824"))
{
$DiskVolumeSpace = "{0:N2}" -f ($DiskVolumeSpace/1024/1024)
$DiskVolumeSpaceUnit = "TB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
elseif ($DiskVolumeSpace -eq $null)
{
$DiskVolumeSpace = "N/A"
$DiskVolumeSpaceUnit = "-"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
else
{
$DiskVolumeSpace = $DiskVolumeSpace
$DiskVolumeSpaceUnit = "MB"
return $DiskVolumeSpace, $DiskVolumeSpaceUnit
}
}
else
{
return "Unknown Parameter"
}
}
# Convert BusType Value to BusType Name
Function sConvert-BusTypeName {
Param ([Byte] $BusTypeValue)
if ($BusTypeValue -eq 1){$Result = "SCSI"}
elseif ($busTypeValue -eq 2){$Result = "ATAPI"}
elseif ($busTypeValue -eq 3){$Result = "ATA"}
elseif ($busTypeValue -eq 4){$Result = "IEEE 1394"}
elseif ($busTypeValue -eq 5){$Result = "SSA"}
elseif ($busTypeValue -eq 6){$Result = "FC"}
elseif ($busTypeValue -eq 7){$Result = "USB"}
elseif ($busTypeValue -eq 8){$Result = "RAID"}
elseif ($busTypeValue -eq 9){$Result = "iSCSI"}
elseif ($busTypeValue -eq 10){$Result = "SAS"}
elseif ($busTypeValue -eq 11){$Result = "SATA"}
elseif ($busTypeValue -eq 12){$Result = "SD"}
elseif ($busTypeValue -eq 13){$Result = "SAS"}
elseif ($busTypeValue -eq 14){$Result = "Virtual"}
elseif ($busTypeValue -eq 15){$Result = "FB Virtual"}
elseif ($busTypeValue -eq 16){$Result = "Storage Spaces"}
elseif ($busTypeValue -eq 17){$Result = "NVMe"}
else {$Result = "Unknown"}
Return $Result
}
# Convert Cluster Disk State Value to Name
Function sConvert-ClusterDiskState {
Param ([Byte] $StateValue)
if ($StateValue -eq 0){$Result = "Inherited",$stateBgColors[5],$stateWordColors[5]}
elseif ($StateValue -eq 1){$Result = "Initializing",$stateBgColors[4],$stateWordColors[4]}
elseif ($StateValue -eq 2){$Result = "Online",$stateBgColors[1],$stateWordColors[1]}
elseif ($StateValue -eq 3){$Result = "Offline",$stateBgColors[2],$stateWordColors[2]}
elseif ($StateValue -eq 4){$Result = "Failed",$stateBgColors[3],$stateWordColors[3]}
elseif ($StateValue -eq 127){$Result = "Offline",$stateBgColors[2],$stateWordColors[2]}
elseif ($StateValue -eq 128){$Result = "Pending",$stateBgColors[4],$stateWordColors[4]}
elseif ($StateValue -eq 129){$Result = "Online Pending",$stateBgColors[4],$stateWordColors[4]}
elseif ($StateValue -eq 130){$Result = "Offline Pending",$stateBgColors[4],$stateWordColors[4]}
else {$Result = "Unknown",$stateBgColors[5],$stateWordColors[5]} # Including "-1" state
Return $Result
}
# Convert BusType Value to BusType Name
Function sConvert-DiskPartitionStyle {
Param ([Byte] $PartitionStyleValue)
if ($PartitionStyleValue -eq 1)
{
$Result = "MBR"
}
elseif ($PartitionStyleValue -eq 2)
{
$Result = "GPT"
}
else
{
$Result = "Unknown"
}
Return $Result
}
# Generate Volume Size Colors
Function sConvert-VolumeSizeColors {
Param ([Byte] $FreePercent)
if (($FreePercent -le 10) -and ($FreePercent -gt 5))
{
$Result = $stateBgColors[4],$stateBgColors[4],$stateWordColors[4]
}
elseif ($FreePercent -le 5)
{
$Result = $stateBgColors[3],$stateBgColors[3],$stateWordColors[3]
}
else
{
$Result = $stateBgColors[0],$stateBgColors[0],"#BDBDBD"
}
Return $Result
}
#endregion Functions
#region Variables
#----------------
# Print MSG
sPrint -Type 1 -Message "Started! Hyper-V Reporting Script (Version 1.5)"
Start-Sleep -Seconds 3
# State Colors
[array]$stateBgColors = "", "#ACFA58","#E6E6E6","#FB7171","#FBD95B","#BDD7EE" #0-Null, 1-Online(green), 2-Offline(grey), 3-Failed/Critical(red), 4-Warning(orange), 5-Other(blue)
[array]$stateWordColors = "", "#298A08","#848484","#A40000","#9C6500","#204F7A","#FFFFFF" #0-Null, 1-Online(green), 2-Offline(grey), 3-Failed/Critical(red), 4-Warning(orange), 5-Other(blue), 6-White
# Date and Time
$Date = Get-Date -Format d/MMM/yyyy
$Time = Get-Date -Format "hh:mm:ss tt"
# Log and report file/folder
$FileTimeSuffix = ((Get-Date -Format dMMMyy).ToString()) + "-" + ((get-date -Format hhmmsstt).ToString())
if ($ReportFileNameTimeStamp)
{
$ReportFile = $ReportFilePath + "\" + $ReportFileNamePrefix + "-" + $FileTimeSuffix + ".html"
}
else
{
$ReportFile = $ReportFilePath + "\" + $ReportFileNamePrefix + ".html"
}
$LogFile = $ReportFilePath + "\" + "ScriptLog" + ".txt"
# Logging enabled
[bool]$Logging = $True
# HighlightsOnly Mode String
$hlString = $null
if ($HighlightsOnly)
{
$hlString = "<center><span style=""padding-top:1px;padding-bottom:1px;font-size:12px;background-color:#FBD95B;color:#FFFFFF""> (HighlightsOnly Mode) </span></center>"
sPrint -Type 1 -Message "HighlightsOnly mode is enabled." -WriteToLogFile $True
}
#endregion Variables
#region Prerequisities Check
#---------------------------
# Log file check and write subject line
if (!(Test-Path -Path $LogFile)) {
New-Item -Path $LogFile -ItemType file -Force -ErrorAction SilentlyContinue | Out-Null
if (Test-Path -Path $LogFile)
{
sPrint -Type 6 -WriteToLogFile $true
sPrint -Type 5 -Message "----- Start -----" -WriteToLogFile $true
sPrint -Type 1 -Message "Logging started: $LogFile" -WriteToLogFile $True
Start-Sleep -Seconds 3
}
else
{
$Logging = $false
sPrint -Type 2 -Message "Unable to create the log file. Script will continue without logging..."
Start-Sleep -Seconds 3
}
}
else {
sPrint -Type 6 -WriteToLogFile $true
sPrint -Type 5 -Message "----- Start -----" -WriteToLogFile $true
sPrint -Type 1 -Message "Logging started: $LogFile" -WriteToLogFile $true
Start-Sleep -Seconds 3
}
# Controls for some important prerequisites
if ((!$VMHost) -and (!$Cluster)) {
sPrint -Type 0 -Message "Hyper-V target parameter is missing. Use -Cluster or -VMHost parameter to define target." -WriteToLogFile $True
sPrint -Type 2 -Message "For technical information, type: Get-Help .\Get-HyperVReport.ps1 -examples" -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
if (($VMHost) -and ($Cluster)) {
sPrint -Type 0 -Message "-Cluster and -VMHost parameters can not be used together." -WriteToLogFile $True
sPrint -Type 2 -Message "For technical information, type: Get-Help .\Get-HyperVReport.ps1 -examples" -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
# Controls for runtime environment operating system version, Hyper-V PowerShell and Clustering PowerShell modules
sPrint -Type 1 -Message "Checking prerequisites to run script on the $($env:COMPUTERNAME.ToUpper())..." -WriteToLogFile $True
$osVersion = $null
$osName = $null
$osVersion = sGet-Wmi -ComputerName $env:COMPUTERNAME -Namespace root\Cimv2 -Class Win32_OperatingSystem -Property Version,Caption
if ($osVersion[1] -eq 1)
{
$osName = $osVersion[0].Caption
$osVersion = $osVersion[0].Version
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): $($osVersion[0])" -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
if ($osVersion)
{
if (($OsVersion -like "6.2*") -or ($OsVersion -like "6.3*"))
{
if ($osName -like "Microsoft Windows 8*")
{
sPrint -Type 5 -Message "$($env:COMPUTERNAME.ToUpper()): Operating system is supported as script runtime environment." -WriteToLogFile $True
# Check Hyper-V PowerShell
if ((Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-Management-PowerShell -Online).State -eq "Enabled")
{
sPrint -Type 5 -Message "$($env:COMPUTERNAME.ToUpper()): Hyper-V PowerShell Module is OK." -WriteToLogFile $True
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): Hyper-V PowerShell Module is not found. Please enable manually and run this script again. You can use `"Turn Windows features on or off`" to enable `"Hyper-V Module for Windows PowerShell`"." -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
# Check Failover Cluster PowerShell
if ($Cluster)
{
if (Get-Hotfix -ID KB2693643 -ErrorAction SilentlyContinue)
{
if ((Get-WindowsOptionalFeature -FeatureName RemoteServerAdministrationTools-Features-Clustering -Online).State -eq "Enabled")
{
sPrint -Type 5 -Message "$($env:COMPUTERNAME.ToUpper()): Failover Clustering PowerShell Module is OK." -WriteToLogFile $True
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): Failover Clustering PowerShell Module is not found. Please enable manually and run this script again. You can use `"Turn Windows features on or off`" to enable `"Failover Clustering Tools`"." -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): Remote Server Administration Tools (RSAT) is not found. Please download (KB2693643) and install manually and run this script again." -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
}
}
else
{
sPrint -Type 5 -Message "$($env:COMPUTERNAME.ToUpper()): Operating system is supported as script runtime environment." -WriteToLogFile $True
# Check Hyper-V PowerShell
if ((Get-WindowsFeature -ComputerName $env:COMPUTERNAME -Name "Hyper-V-PowerShell").Installed)
{
sPrint -Type 5 -Message "$($env:COMPUTERNAME.ToUpper()): Hyper-V PowerShell Module is OK." -WriteToLogFile $True
}
else
{
sPrint -Type 2 -Message "$($env:COMPUTERNAME.ToUpper()): Hyper-V PowerShell Module is not found." -WriteToLogFile $True
sPrint -Type 2 -Message "$($env:COMPUTERNAME.ToUpper()): Installing Hyper-V PowerShell Module... " -WriteToLogFile $True
Start-Sleep -Seconds 3
Add-WindowsFeature -Name "Hyper-V-PowerShell" -ErrorAction SilentlyContinue | Out-Null
if ((Get-WindowsFeature -ComputerName $env:COMPUTERNAME -Name "Hyper-V-PowerShell").Installed)
{
sPrint -Type 1 -Message "$($env:COMPUTERNAME.ToUpper()): Hyper-V PowerShell Module is OK." -WriteToLogFile $True
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): Hyper-V PowerShell Module could not be installed. Please install it manually." -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
}
# Check Failover Cluster PowerShell
if ($Cluster)
{
if ((Get-WindowsFeature -ComputerName $env:COMPUTERNAME -Name "RSAT-Clustering-PowerShell").Installed)
{
sPrint -Type 5 -Message "$($env:COMPUTERNAME.ToUpper()): Failover Clustering PowerShell Module is OK." -WriteToLogFile $True
}
else
{
sPrint -Type 2 -Message "$($env:COMPUTERNAME.ToUpper()): Failover Clustering PowerShell Module is not found." -WriteToLogFile $True
sPrint -Type 2 -Message "$($env:COMPUTERNAME.ToUpper()): Installing Failover Clustering PowerShell Module..." -WriteToLogFile $True
Start-Sleep -Seconds 3
Add-WindowsFeature -Name "RSAT-Clustering-PowerShell" | Out-Null
if ((Get-WindowsFeature -ComputerName $env:COMPUTERNAME -Name "RSAT-Clustering-PowerShell").Installed)
{
sPrint -Type 1 -Message "$($env:COMPUTERNAME.ToUpper()): Failover Clustering PowerShell Module is OK." -WriteToLogFile $True
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): Failover Clustering PowerShell Module could not be installed. Please install it manually." -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!"
Break
}
}
}
}
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): Incompatible operating system version detected. Supported operating systems are Windows Server 2012 and Windows Server 2012 R2." -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
}
else
{
sPrint -Type 0 -Message "$($env:COMPUTERNAME.ToUpper()): Could not detect operating system version." -WriteToLogFile $True
sPrint -Type 0 -Message "Script terminated!" -WriteToLogFile $True
Break
}
# Special Thanks to Serhat Akinci
$Computers = $null
$ClusterName = $null
[array]$VMHosts = $null
#endregion Prerequisities Check
#region HTML Start
#----------------
# HTML Head
$outHtmlStart = "<!DOCTYPE html>
<html>
<head>
<title>ghostinthewires Internal Hyper-V Environment Report</title>
<style>
/*Reset CSS*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary,
time, mark, audio, video {margin: 0;padding: 0;border: 0;font-size: 100%;font: inherit;vertical-align: baseline;}
ol, ul {list-style: none;}
blockquote, q {quotes: none;}
blockquote:before, blockquote:after,
q:before, q:after {content: '';content: none;}
table {border-collapse: collapse;border-spacing: 0;}
/*Reset CSS*/
body{
width:100%;
min-width:1024px;
font-family: Verdana, sans-serif;
font-size:14px;
/*font-weight:300;*/
line-height:1.5;
color:#222222;
background-color:#fcfcfc;
}
p{
color:222222;
}
strong{
font-weight:600;
}
h1{
font-size:30px;
font-weight:300;
}
h2{
font-size:20px;
font-weight:300;
}
#ReportBody{
width:95%;
height:500;
/*border: 1px solid;*/
margin: 0 auto;
}
.Overview{
width:100%;
min-width:1280px;
margin-bottom:30px;
}
.OverviewFrame{