{"id":39,"date":"2015-01-24T19:24:33","date_gmt":"2015-01-25T00:24:33","guid":{"rendered":"http:\/\/packetlost.com\/blog\/?p=39"},"modified":"2017-02-07T21:41:05","modified_gmt":"2017-02-08T02:41:05","slug":"vmware-tools-check-powercli-email-report","status":"publish","type":"post","link":"https:\/\/packetlost.com\/blog\/2015\/01\/24\/vmware-tools-check-powercli-email-report\/","title":{"rendered":"VMware Tools Check &#8211; PowerCLI Email Report"},"content":{"rendered":"<p>The last two posts I made utilize PowerCLI and VMware tools to gather information for reporting. So what happens if VMware tools is not running&#8230;. things fall through the cracks!<\/p>\n<p>Luckily, we can report on VMware tools status too.<\/p>\n<pre class=\"lang:ps decode:true \">#Timestamp the transcript and start it\r\n$currentdate = (Get-Date).tostring(\"yyyy-MM-dd\")\r\n$transfilename = 'ToolsRunningCheck_' + $currentdate + '.txt'\r\n$transfilepath = 'C:\\scripts\\Transcripts\\' + $transfilename\r\nStart-Transcript $transfilepath -NoClobber -Append\r\n\r\n#Load PowerCLI snapins and dot source them\r\nAdd-PSSnapin vmware.vimautomation.core\r\n. \"C:\\Program Files (x86)\\VMware\\Infrastructure\\vSphere PowerCLI\\Scripts\\Initialize-PowerCLIEnvironment.ps1\"\r\n\r\n\r\nConnect-VIServer vcenterserver.company.com\r\n\r\n#Generating timestamped log name for powercli html output\r\n$outfilename = 'ToolsRunningCheck_' + $currentdate + '.htm'\r\n$outfilepath = 'C:\\Scripts\\Output\\' + $outfilename\r\n\r\n$PoweredOnVMs = Get-VM | Where-Object {$_.PowerState -eq \"PoweredOn\"}\r\n\r\n$VMswithoutRunningTools = $PoweredOnVMs | Get-View | Where-Object {($_.Guest.ToolsStatus -match \"toolsNotInstalled\") -or ($_.Guest.ToolsStatus -match \"toolsNotRunning\") }   | Select-Object Name,@{Name=\"Status\";Expression={$_.Guest.ToolsStatus}}\r\n\r\nif ($VMswithoutRunningTools) { $VMswithoutRunningTools | Sort-Object Name | ConvertTo-Html | Out-File $outfilepath }\r\n\r\n#variables for email output\r\n$eto = \"youremail@company.com\"\r\n$efrom = \"PowerCLI_Reports &lt;PowerCLIReports@company.com&gt;\"\r\n$esubject = \"Virtual Machines with VMware Tools problems\"\r\nIf ($VMswithoutRunningTools) { $ebody = (Get-Content $outfilepath | Out-String) }\r\n$eserver = \"smtpserver.company.com\"\r\n\r\n\r\n\r\n\r\nIf ($VMswithoutRunningTools) { Send-MailMessage -From $efrom -To $eto -Subject $esubject -BodyAsHtml -Body $ebody -smtpserver $eserver }\r\nElse { Send-MailMessage -From $efrom -To $eto  -Subject $esubject -Body \"There are no VMs reporting VMware Tools is not installed\" -smtpserver $eserver }\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The last two posts I made utilize PowerCLI and VMware tools to gather information for reporting. So what happens if VMware tools is not running&#8230;. things fall through the cracks! Luckily, we can report on VMware tools status too. #Timestamp &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/packetlost.com\/blog\/2015\/01\/24\/vmware-tools-check-powercli-email-report\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,2,16],"tags":[18,3,21],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-powercli","category-powershell","category-vmware","tag-powercli","tag-powershell","tag-vmware-tools"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":1,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":40,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/posts\/39\/revisions\/40"}],"wp:attachment":[{"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/packetlost.com\/blog\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}