VMware Cloud Community
shinpad
Contributor
Contributor
Jump to solution

Script for VMTools status

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

Reply
0 Kudos
24 Replies
Praeliux
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
Praeliux
Contributor
Contributor
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
edelldieguez
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos