A script to find VMs without custom specs workaround applied

This is only pertaining to environments that are on build 1743533 in ESX 5.1

For more information, see my post detailing the critical bug with using custom specs in this build version.

 

The goal of this script was to query vcenter and pull back all windows servers that have a value for a certain property. If this property is populated, custom specs could re-run at any time which will screw you VM up. If the script finds any VMs with a value, it will send you an email notifying you.

 

* Be sure to enter your own info anywhere you see: <enter name>

__________________________________________________________________________________

##############################################################################################################################
##############################################################################################################################
#
# Author: Adam Akers
# Date Created: 9.26.2014
# Last Modified:
# Description:
# This script queries vCenter for all Windows Servers (in Dev and Prod clusters) and checks to make sure they don't have anything
# under Get-AdvancedSetting -Name tools.deploypkg.filename | select -expandproperty "value"
# If there is content under this property, custom specs could run again and sysprep the machine again. This is a known bug in
# current version of ESX we are on - build 1743533. Once we are off this build we won't have to worry about it anymore.
# For more info, see: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2078352
# If it finds something it will email you
#
##############################################################################################################################
##############################################################################################################################

cls

$startTime = Get-Date

# vCenter Server specification
$vCenter = "<enter name>"

# Cluster specification
$devcluster = "<enter name>"
$prodcluster = "<enter name>"

# SMTP information
$sendFrom = "<enter name>"
$sendTo = "<enter name>"
$smtp = "<enter name>"
$msg = $null

#Build email function
function FunSendEmailAlert{
    $subject = "** one or more servers needs attention in vmware! **"
    $body = "Please apply the 'Custom specs workaround' to the following server(s):`n`n`n"
    $body = $body + $msg
    $body = $body + "`n`n`n *** For more information on the workaround, see this kb article: `n `n http://kb.vmware.com/selfservice/microsites/search.do?        language=en_US&cmd=displayKC&externalId=2078352"
    Send-MailMessage -from $sendFrom -to $sendTo -subject $subject -body $body -smtpserver $smtp
    }
# END function

add-pssnapin VMware.VimAutomation.Core
Write-Output "Stand by, connecting to $vcenter…."
Connect-VIServer -Server $vCenter

$VMs = get-cluster $devcluster,$prodcluster | Get-vm | where {($_.extensiondata.config.Guestfullname -like "*Microsoft Windows Server*")} | ForEach-Object {get-vm $_.name | Get-AdvancedSetting -Name tools.deployPkg.fileName} | select entity,value

$Vms | ForEach-Object {
    $VM = $_
    $value = $VM | select -expandproperty "value"
    $vmname = $VM.entity.name

    If ($value -eq "")
        {return}
    If($value -like "*.tmp")
        {$msg += "$VMname`n`n"}
    }

# Disconnect from vCenter Server
Write-Output "Stand by, disconnecting from $vCenter"
Disconnect-VIServer $vCenter -Confirm:$False

$endTime = Get-Date
Write-Host "Done at $endTime. Time for the full run was: $( New-TimeSpan $startTime $endTime)."

## Send email if it finds a VM that needs attention
If ($msg -ne $null)
    {FunSendEmailAlert}

_____________________________________________________________________________________

akers8806

Leave a Reply

Your email address will not be published. Required fields are marked *