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…. things fall through the cracks!
Luckily, we can report on VMware tools status too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#Timestamp the transcript and start it $currentdate = (Get-Date).tostring("yyyy-MM-dd") $transfilename = 'ToolsRunningCheck_' + $currentdate + '.txt' $transfilepath = 'C:\scripts\Transcripts\' + $transfilename Start-Transcript $transfilepath -NoClobber -Append #Load PowerCLI snapins and dot source them Add-PSSnapin vmware.vimautomation.core . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" Connect-VIServer vcenterserver.company.com #Generating timestamped log name for powercli html output $outfilename = 'ToolsRunningCheck_' + $currentdate + '.htm' $outfilepath = 'C:\Scripts\Output\' + $outfilename $PoweredOnVMs = Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} $VMswithoutRunningTools = $PoweredOnVMs | Get-View | Where-Object {($_.Guest.ToolsStatus -match "toolsNotInstalled") -or ($_.Guest.ToolsStatus -match "toolsNotRunning") } | Select-Object Name,@{Name="Status";Expression={$_.Guest.ToolsStatus}} if ($VMswithoutRunningTools) { $VMswithoutRunningTools | Sort-Object Name | ConvertTo-Html | Out-File $outfilepath } #variables for email output $eto = "youremail@company.com" $efrom = "PowerCLI_Reports <PowerCLIReports@company.com>" $esubject = "Virtual Machines with VMware Tools problems" If ($VMswithoutRunningTools) { $ebody = (Get-Content $outfilepath | Out-String) } $eserver = "smtpserver.company.com" If ($VMswithoutRunningTools) { Send-MailMessage -From $efrom -To $eto -Subject $esubject -BodyAsHtml -Body $ebody -smtpserver $eserver } Else { Send-MailMessage -From $efrom -To $eto -Subject $esubject -Body "There are no VMs reporting VMware Tools is not installed" -smtpserver $eserver } |
0 Comments.