This example sends an email in HTML format for each vCenter.
You can add additional script in the same way as scripts 1,2 and 3 are done.
Each script produces a fragment of the report.
You can change the style to whatever you want, this is just an example.
$vcenters = 'vc1','vc2','vc3'$style = @'
<style>
body { background-color:#E5E4E2;
font-family:Monospace;
font-size:10pt; }
td, th { border:0px solid black;
border-collapse:collapse;
white-space:pre; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px ;white-space:pre; }
tr:nth-child(odd) {background-color: lightgray}
table { width:95%;margin-left:5px; margin-bottom:20px;}
h2 {
font-family:Tahoma;
color:#6D7B8D;
}
.alert {
color: red;
}
.footer
{ color:green;
margin-left:10px;
font-family:Tahoma;
font-size:8pt;
font-style:italic;
}
</style>
'@
$now = Get-Date
Connect-VIServer -Server $vcenters
$global:defaultVIServers | ForEach-Object -Process {
$fragments = @()
# Report Title
$fragments += "<H1>vCenter $([string]($_.Name))</H1>"
# Script 1
$fragments += Get-VIEvent -Server $_ -Start $now.AddHours(-1) -MaxSamples ([int]::MaxValue) |
where { $_ -is [VMware.Vim.DrsVmMigratedEvent] } |
Select CreatedTime, @{N = 'VM'; E = { $_.Vm.Name } },
@{N = 'From'; E = { $_.SourceHost.Name } },
@{n = 'To'; E = { $_.Host.Name } } |
Sort-Object -Property CreatedTime |
ConvertTo-Html -Fragment -PreContent "<H2>DRS vMotion</H2>"
# Script 2
$fragments += Get-VMHost -Server $_ | Get-VMHostNetworkAdapter -Physical -VMKernel:$false |
Select @{N = 'VMHost'; E = { $_.VMHost.Name } }, Name, BitRatePerSec, FullDuplex, Mac |
Sort-Object -Property VMHost, Name |
ConvertTo-Html -Fragment -PreContent "<H2>pNIC Configuration</H2>"
# Script 3
$fragments += Get-VMHost -Server $_ | where { $_.State -eq 'maintenance' } |
Select @{N = 'VMHost'; E = { $_.Name } }, State |
Sort-Object -Property VMHost, Name |
ConvertTo-Html -Fragment -PreContent "<H2>Hosts in maintenance mode</H2>"
# Send email
$sMail = @{
From = 'me@domain'
To = 'you@domain'
Subject = 'Report'
SmtpServer = 'mail.domain'
BodyAsHtml = $true
Body = ConvertTo-Html -Head $style -Body $fragments | Out-String
}
Send-MailMessage @sMail
}
Disconnect-VIServer -Server $vcenters -Confirm:$false