if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSsnapin VMware.VimAutomation.Core
}
$server = "Server001"
$SMTPserver = "emailserv.mydomain.co.uk"
$from = "sendermailer@mydomain.co.uk"
$to = "sterlinghd@mydomain.co.uk"
$attachments = "C:\Scripts\Generate-VMToolsVersionReport\VMWareTools_VersionReport.txt"
$subject = "VMWare Tools Report from vc001 server Cluster"
$bodytext = "Attachment contains the current versions of VMWare tools by VM on the vc001 Vcenter cluster"
# Connect to the vCenter server(s)
$vcserver = connect-VIServer $server -Protocol https -WarningAction SilentlyContinue | Out-Null
# get the vmware tools version for each VM
get-vm | % { get-view $_.ID } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}} | Sort-Object toolsversion -Descending | out-file $attachments
# Disconnect from the vCenter server(s)
Disconnect-VIServer -Server $server -Force:$true -Confirm:$false
$mailer = New-Object Net.Mail.SMTPclient($SMTPserver)
$msg = New-Object Net.Mail.MailMessage($from, $to, $subject, $bodytext)
$Attach = new-object Net.Mail.Attachment($attachments)
$msg.Attachments.Add($attach)
$mailer.send($msg)
Do more with
if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSsnapin VMware.VimAutomation.Core
}
$server = "Server001"
$SMTPserver = "emailserv.mydomain.co.uk"
$from = "sendermailer@mydomain.co.uk"
$to = "sterlinghd@mydomain.co.uk"
$attachments = "C:\Scripts\Generate-VMToolsVersionReport\VMWareTools_VersionReport.txt"
$subject = "VMWare Tools Report from vc001 server Cluster"
# Connect to the vCenter server(s)
$vcserver = connect-VIServer $server -Protocol https -WarningAction SilentlyContinue | Out-Null
# get the vmware tools version for each VM
get-vm | % { get-view $_.ID } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}} | Sort-Object toolsversion -Descending | out-file $attachments
$bodytext = [string]::Join("`r`n",(Get-Content $attachments))
# Disconnect from the vCenter server(s)
Disconnect-VIServer -Server $server -Force:$true -Confirm:$false
$mailer = New-Object Net.Mail.SMTPclient($SMTPserver)
$msg = New-Object Net.Mail.MailMessage($from, $to, $subject, $bodytext)
$Attach = new-object Net.Mail.Attachment($attachments)
$msg.Attachments.Add($attach)
$mailer.send($msg)
Premium Content
You need an Expert Office subscription to comment.Start Free Trial