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 .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. 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 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. 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. 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 #region Global script settings and variables
#General #General
$Version = "v1.0" $Version = "v1.1"
$logfilelocation = "$($MyInvocation.MyCommand.Path | Split-Path -Parent)\Logs" $logfilelocation = "$($MyInvocation.MyCommand.Path | Split-Path -Parent)\Logs"
$logfilename = "$(Get-Date -Format yyyyMMddHHmmss).log" $logfilename = "$(Get-Date -Format yyyyMMddHHmmss).log"
$summaryfilename = "$(Get-Date -Format yyyyMMddHHmmss)-Summary.txt" $summaryfilename = "$(Get-Date -Format yyyyMMddHHmmss)-Summary.txt"
@@ -44,6 +43,7 @@
$STR_EmailSubject= "Hyper-V Status Report - $(Get-Date -Format "dd-MM-yyyy")" $STR_EmailSubject= "Hyper-V Status Report - $(Get-Date -Format "dd-MM-yyyy")"
$STR_SMTPFromaddress = "ICT Servicedesk <servicedesk@contoso.com>" $STR_SMTPFromaddress = "ICT Servicedesk <servicedesk@contoso.com>"
$STR_Receivers = "servicedesk@contoso.com,systemengineer1@contoso.com" #List of commaseperated emailaddresses $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 #endregion
#region functions #region functions
@@ -285,74 +285,79 @@
$htmlReport += "</table>" $htmlReport += "</table>"
#Generate VM Replication Health table #Generate VM Replication Health table
$htmlReport += @" if ($VMreplinfo | Where-Object {$_.HVServer -eq $hvserver}) {
<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})) {
$htmlReport += @" $htmlReport += @"
<h3>Server: $hvserver - VM Replication Health</h3>
$(switch ($vm.ReplicationHealth){ <table border='1'>
'Critical' {"<tr bgcolor='Red'>"} <tr>
'Warning' {"<tr bgcolor='Yellow'>"} <th>VM Name</th>
default {"<tr>"} <th>State</th>
} ) <th>Health</th>
<td>$($vm.VMName)</td> <th>LastReplicationTime</th>
<td>$($vm.ReplicationState)</td> <th>PrimaryServer</th>
<td>$($vm.ReplicationHealth)</td> <th>ReplicaServer</th>
<td>$($vm.LastReplicationTime)</td> <th>Mode</th>
<td>$($vm.PrimaryServer)</td> <th>Relation</th>
<td>$($vm.ReplicaServer)</td> </tr>
<td>$($vm.ReplicationMode)</td>
<td>$($vm.RelationshipType)</td>
</tr>
"@ "@
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>"
} }
$htmlReport += "</table>"
#Generate VM Metric details table #Generate VM Metric details table
$htmlReport += @" if ($VMmetricinfo | Where-Object {$_.HVServer -eq $hvserver}) {
<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 += @" $htmlReport += @"
<h3>Server: $hvserver - VM Metric details</h3>
$(switch ($vm.ReplicationHealth){ <table border='1'>
'Critical' {"<tr bgcolor='Red'>"} <tr>
'Warning' {"<tr bgcolor='Yellow'>"} <th>VM Name</th>
default {"<tr>"} <th>Average CPU Utilization (MHz)</th>
} ) <th>Average Memory (GB)</th>
<td>$($vm.VMName)</td> <th>Disk Space Used (GB)</th>
<td>$($vm.AvgCPU)</td> <th>Inbound Network Traffic (GB)</th>
<td>$($vm.AvgRAM)</td> <th>Outbound Network Traffic (GB)</th>
<td>$($vm.TotalDisk)</td> <th>Metering data duration</th>
<td>$($vm.InboundNWTraffic)</td> </tr>
<td>$($vm.OutboundNWTraffic)</td>
<td>$($vm.MeteringDuration)</td>
</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 += @" $htmlReport += @"
<p><i>This is an automated report.</i></p> <p><i>This is an automated report.</i></p>
@@ -372,5 +377,9 @@
else { else {
$subject = "$STR_EmailSubject" $subject = "$STR_EmailSubject"
} }
SendMailv2 -To $STR_Receivers -Subject $subject -Body $htmlReport SendMailv2 -To $STR_Receivers -Subject $subject -Body $htmlReport
if ($reportstatus -ne "OK") {
SendMailv2 -To $STR_AdminReceivers -Subject $subject -Body $htmlReport
}
#endregion #endregion