When i presented the result from a vSphere health check the other day my costumer was quite surprised that a few of his virtual machines had an installed guest operating system that didn’t match the guest operation system configured in vSphere.
Several other blogs covers the importance of having a configured guest operating system in vSphere that matches the guest operating system running in the virtual machine so i will not cover that in detail in my blog post. You will e.g. get the correct VMware Tools version based on your configured guest operating system.
My customer asked me to create an process that verifies if any virtual machine has a configured guest operating system that does not match the installed guest operating system. If the process found any mismatch he wants the process to:
- Log the virtual machine names to a file.
- Send the file in an e-mail to a specific e-mail address.
Below you’ll find the PowerCLI script i implemented in my customers environment that is running vSphere 5.1 U1.
Change the following parameters in the below script to match your environment:
- $vcenter = “vc01.vcdx56.local”
- $vcenteruser = “vcdx56\magnus”
- $vcenterpw = “not secret”
- $sendTo = “magnus@vcdx56.local”
- $sendFrom = “vc-demo01@vcdx56.local”
- $smtpserver = “smtp.vcdx56.local”
# Compare vSphere configured guest operating system with the guest operating system running within the virtual machines # Version 1.0 Magnus Andersson RTS #———————————————— # Start of script parameters section $date = get-date -uformat %Y-%m-%d $outfile="c:VIreportsVM-configured-and-installed-guest-OS.html_$date.html" # # vCenter Server configuration $vcenter = "vc01.vcdx56.local" $vcenteruser = "vcdx56\magnus" $vcenterpw = "not secret" # # SMTP configuration $sendTo = "magnus@vcdx56.local" $sendFrom = "vc-demo01@vcdx56.local" $smtpserver = "smtp.vcdx56.local" # # End of script parameter section #—————————————— # Connect to vcenter Server connect-viserver $vcenter -User $vcenteruser -Password $vcenterpw # # Get-View -ViewType "VirtualMachine" -Property @("Name", "Config.GuestFullName", "Guest.GuestFullName") |Where-Object {($_.Config.GuestFullName -ne $_.Guest.GuestFullName) -and ($_.Guest.GuestFullName -ne $null)} | Select-Object -Property Name, @{N="Configured OS";E={$_.Config.GuestFullName}}, @{N="Running OS";E={$_.Guest.GuestFullName}} | ConvertTo-HTML |Out-File $outfile # # # Send e-mail report send-mailmessage -to $sendTo -from $sendFrom -Subject "Virtual Machine configured and installed guest operating system report" -smtpserver $smtpserver -Attachments $outfile
This is the e-mail report, with open attachment, you’ll receive when the script is finished.
1 pings