HI all,
I am looking for a script which I run from a VC, and it generate all these information in one file per VC wise into single report, and then send report to email. The script for below tasks will show the report for
- Number of VMs migrated through DRS in last 24 hours.
- Physical adapter Status of ESXi Hosts
- List of Host in maintenance mode
- List of Datastores over provisioned
- New VMs created in last 24 hours
- VMs removed in last 24 hours
- Snapshot report
- Snapshot older than 72 hours
- Storage VMotion
$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
Thanks
V