2
0

v1.1 added admin receivers and if statements for table creation

This commit is contained in:
2024-07-24 09:36:16 +02:00
parent 0ba5d9c93f
commit b07effeed5

View File

@@ -12,7 +12,6 @@
.NOTES
This script is intended for use in a test or production environment. Make sure to test the script in a non-production environment before running it in production.
Author: D.de Kooker - info@dcomputers.nl
Version: 1.0
DISCLAIMER: Use scripts at your own risk, if there is anything I can help you with I will try but I do not take responsibility for the way that anyone else uses my scripts.
Sharing is caring. Share your knowledge with the world so that everybody can learn from it.
@@ -31,7 +30,7 @@
#region Global script settings and variables
#General
$Version = "v1.0"
$Version = "v1.1"
$logfilelocation = "$($MyInvocation.MyCommand.Path | Split-Path -Parent)\Logs"
$logfilename = "$(Get-Date -Format yyyyMMddHHmmss).log"
$summaryfilename = "$(Get-Date -Format yyyyMMddHHmmss)-Summary.txt"
@@ -44,6 +43,7 @@
$STR_EmailSubject= "Hyper-V Status Report - $(Get-Date -Format "dd-MM-yyyy")"
$STR_SMTPFromaddress = "ICT Servicedesk <servicedesk@contoso.com>"
$STR_Receivers = "servicedesk@contoso.com,systemengineer1@contoso.com" #List of commaseperated emailaddresses
$STR_AdminReceivers = "servicedesk@contoso.com,systemengineer1@contoso.com" #list of additional emailaddresses that receive Warning and Error mails only
#endregion
#region functions
@@ -285,74 +285,79 @@
$htmlReport += "</table>"
#Generate VM Replication Health table
$htmlReport += @"
<h3>Server: $hvserver - VM Replication Health</h3>
<table border='1'>
<tr>
<th>VM Name</th>
<th>State</th>
<th>Health</th>
<th>LastReplicationTime</th>
<th>PrimaryServer</th>
<th>ReplicaServer</th>
<th>Mode</th>
<th>Relation</th>
</tr>
"@
foreach ($vm in ($VMreplinfo | Where-Object {$_.HVServer -eq $hvserver})) {
if ($VMreplinfo | Where-Object {$_.HVServer -eq $hvserver}) {
$htmlReport += @"
$(switch ($vm.ReplicationHealth){
'Critical' {"<tr bgcolor='Red'>"}
'Warning' {"<tr bgcolor='Yellow'>"}
default {"<tr>"}
} )
<td>$($vm.VMName)</td>
<td>$($vm.ReplicationState)</td>
<td>$($vm.ReplicationHealth)</td>
<td>$($vm.LastReplicationTime)</td>
<td>$($vm.PrimaryServer)</td>
<td>$($vm.ReplicaServer)</td>
<td>$($vm.ReplicationMode)</td>
<td>$($vm.RelationshipType)</td>
</tr>
<h3>Server: $hvserver - VM Replication Health</h3>
<table border='1'>
<tr>
<th>VM Name</th>
<th>State</th>
<th>Health</th>
<th>LastReplicationTime</th>
<th>PrimaryServer</th>
<th>ReplicaServer</th>
<th>Mode</th>
<th>Relation</th>
</tr>
"@
}
$htmlReport += "</table>"
foreach ($vm in ($VMreplinfo | Where-Object {$_.HVServer -eq $hvserver})) {
$htmlReport += @"
$(switch ($vm.ReplicationHealth){
'Critical' {"<tr bgcolor='Red'>"}
'Warning' {"<tr bgcolor='Yellow'>"}
default {"<tr>"}
} )
<td>$($vm.VMName)</td>
<td>$($vm.ReplicationState)</td>
<td>$($vm.ReplicationHealth)</td>
<td>$($vm.LastReplicationTime)</td>
<td>$($vm.PrimaryServer)</td>
<td>$($vm.ReplicaServer)</td>
<td>$($vm.ReplicationMode)</td>
<td>$($vm.RelationshipType)</td>
</tr>
"@
}
$htmlReport += "</table>"
}
#Generate VM Metric details table
$htmlReport += @"
<h3>Server: $hvserver - VM Metric details</h3>
<table border='1'>
<tr>
<th>VM Name</th>
<th>Average CPU Utilization (MHz)</th>
<th>Average Memory (GB)</th>
<th>Disk Space Used (GB)</th>
<th>Inbound Network Traffic (GB)</th>
<th>Outbound Network Traffic (GB)</th>
<th>Metering data duration</th>
</tr>
"@
foreach ($vm in ($VMmetricinfo | Where-Object {$_.HVServer -eq $hvserver})) {
if ($VMmetricinfo | Where-Object {$_.HVServer -eq $hvserver}) {
$htmlReport += @"
$(switch ($vm.ReplicationHealth){
'Critical' {"<tr bgcolor='Red'>"}
'Warning' {"<tr bgcolor='Yellow'>"}
default {"<tr>"}
} )
<td>$($vm.VMName)</td>
<td>$($vm.AvgCPU)</td>
<td>$($vm.AvgRAM)</td>
<td>$($vm.TotalDisk)</td>
<td>$($vm.InboundNWTraffic)</td>
<td>$($vm.OutboundNWTraffic)</td>
<td>$($vm.MeteringDuration)</td>
</tr>
<h3>Server: $hvserver - VM Metric details</h3>
<table border='1'>
<tr>
<th>VM Name</th>
<th>Average CPU Utilization (MHz)</th>
<th>Average Memory (GB)</th>
<th>Disk Space Used (GB)</th>
<th>Inbound Network Traffic (GB)</th>
<th>Outbound Network Traffic (GB)</th>
<th>Metering data duration</th>
</tr>
"@
foreach ($vm in ($VMmetricinfo | Where-Object {$_.HVServer -eq $hvserver})) {
$htmlReport += @"
$(switch ($vm.ReplicationHealth){
'Critical' {"<tr bgcolor='Red'>"}
'Warning' {"<tr bgcolor='Yellow'>"}
default {"<tr>"}
} )
<td>$($vm.VMName)</td>
<td>$($vm.AvgCPU)</td>
<td>$($vm.AvgRAM)</td>
<td>$($vm.TotalDisk)</td>
<td>$($vm.InboundNWTraffic)</td>
<td>$($vm.OutboundNWTraffic)</td>
<td>$($vm.MeteringDuration)</td>
</tr>
"@
}
$htmlReport += "</table>"
}
$htmlReport += "</table>"
}
$htmlReport += @"
<p><i>This is an automated report.</i></p>
@@ -372,5 +377,9 @@
else {
$subject = "$STR_EmailSubject"
}
SendMailv2 -To $STR_Receivers -Subject $subject -Body $htmlReport
if ($reportstatus -ne "OK") {
SendMailv2 -To $STR_AdminReceivers -Subject $subject -Body $htmlReport
}
#endregion