VMware Cloud Community
vmk2014
Expert
Expert

Health report

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

Tags (1)
2 Replies
LucD
Leadership
Leadership

This is amazing.

In the thread from which you copied this, I suggested to search this community, and now you just come back with the same question.

This thread holds nine (9) different questions and 3 possible solutions.
Don't you think that is a bit over the top for one thread?

I would advise having a read of Chip's document How To Ask For Help On Tech Forums

This community is not a script-ordering-service for your benefit.
I try to help everyone with questions and issues, but I see some people always asking for complex scripts and never showing that they are actually learning and progressing.

For all others who might read this, I have lately been using a couple of rules for myself
Which might explain why you could feel ignored by me.

Time to make some of my rules public I guess


- if you submit threads to which I answer, but you don't feel the need to reply or indicate it solved your issue, after maximum three such events, your next questions will be ignored by me
- a community is for the benefit of all. Indicating that a question is answered helps others to find answered questions

- a thread should be about a single issue. Again, packaging multiple questions in one thread, makes it difficult for others to find and harder for anyone to answer.
- when a thread's question has been answered, don't keep appending other questions. Open a new thread for a new question

- don't piggy-back on existing threads. Rather open a new thread and eventually refer to an existing thread
- show in your thread that you at least invested some time on it. Mine is not a scripting service at your desire. My hourly rates would, in any case, blow you away :smileygrin:
- I understand that everyone needs to learn stuff, but if you are still asking beginner's questions after a couple of years, you're not showing your intention to learn

And some guidelines (most of which probably also feature in some form or another in Chip's document)

- provide information when you open a thread. The line "I have a problem" doesn't suffice. Provide platforms, versions ...whatever which might help anyone to answer your question
- I understand English might not be your native language, but try to make your questions at least not too imperative. A thread starting with "I need..." or "Provide me this script" will probably be ignored by me.
- a thread starting with "My manager/boss/customer wants me ..." doesn't increase the priority of your thread. If you feel you're not able to do what you are asked to do, there is a lack of training, not something a community board can fix.
- please use the Search facility of this board. With +15000 threads, chances are pretty high, your question was already answered
- please don't insert hundreds of lines of output in a thread, there is this handy Attach feature
- a screenshot often helps to explain an issue better than a thousand words


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vmk2014
Expert
Expert

Hi LucD,

I agree with you. I'll try to search your old thread, but the old thread mostly includes event based thread. Example - VM's deleted or created in last 7 days, but the  name of VM's created and created by user is missing. But still, kudos to you for VM's vCheck created and deleted last 7 days. All your previous thread helped me a lot specially for vCheck report which i'm using for remote site monitoring because of you.

However, i'll again try to find your old thread and will see if it works as you mentioned "please use the Search facility of this board. With +15000 threads, chances are pretty high, your question was already answered"

Thank you.

V

0 Kudos