shinpad
Contributor
Contributor

Script for VMTools status

Jump to solution

i've been trying to write a script to check all powered on VMs and then email me a list of VMs where tools are not installed or not running.

i've not been able to do it, so can anyone help??

thanks

0 Kudos
24 Replies
Praeliux
Contributor
Contributor

I ran into an issue that maybe you can help with.

I downloaded the tools-report-mail.ps1 and ran it against my environment, but it returned the following error:

PS C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts> .\tools-report-mail.ps1

Exception calling "Send" with "1" argument(s): "Failure sending mail."

At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\tools-report-mail.ps1:14 char:11

+ $smtp.send <<<< ($msg)

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

Any suggestions??

Thanks in advance,

Praeliux

0 Kudos
LucD
Leadership
Leadership

You have to specify the FQDN of your SMTP server in the variable $smtpSrv.

If the name does not point to a SMTP server, you get that message.


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

0 Kudos
Praeliux
Contributor
Contributor

I have been assured that the server name I am using is the FQDN for our SMTP mail relay (which is load balanced), and I even tried another single mail relay which has worked in the past, but it still fails with the same result.

Is there a way to query the variable $smtpSrv (and by design check the other variables) to see what it resolves to?

0 Kudos
LucD
Leadership
Leadership

Perhaps you're not authorised from your PC to submit emails to the SMTP server ?

You can check by doing a

telnet fqdn 25

from a DOS box.

You should see some kind of SMTP Server banner appearing on screen.


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

0 Kudos
edelldieguez
Contributor
Contributor

Hi Guys,

Sorry for post here bur its related.

I'm using this script and it does work however I don't get in the email VMs that are turn off, is anyway I can do this?.

$smtpSrv = "mail.VM.com"
$from = "vmware.report@VM.com"
$to = "VM@VM.com"
$subject = "Tools Status Report"
$body = Get-VM | where {$_.PowerState -ne "PoweredOff" -and $_.Guest.State -ne "NotRunning" } | `
     Select Name,
         @{N="Tools version";E={$_.ExtensionData.Guest.ToolsVersion}},      
         @{N="Tools version  status";E={$_.ExtensionData.Guest.ToolsVersionStatus}},
         @{N="Tools running  status";E={$_.ExtensionData.Guest.ToolsRunningStatus}}
if($body){
     $body = $body | ConvertTo-Html
     $msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
     $smtp = new-object Net.Mail.SMTPclient($smtpSrv)
     $msg.IsBodyHTML = $true
     $smtp.send($msg)
}

Thanks in advance.

0 Kudos