VMware tools upgrade script modification

I have 50 vm machines, I add all 50 machines to a file and run powershell script. But output comes saying all 50 machines upgraded.

Script below:
#add this line so powershell knows to treat this as powerCLI
add-pssnapin VMware.VimAutomation.Core

$Server = “”
$user = “”
$pwd = “”
$date = get-date

$connect = Connect-VIServer $server -User $user -Password $pwd

#Import vm name from csv file
Import-Csv deploy.csv |
foreach {
$strNewVMName = $_.name

#Update VMtools without reboot
Get-VM $strNewVMName | Update-Tools -RunAsync
write-host "Updated $strNewVMName ------ "

$report += $strNewVMName+ “`r`n”
write-host “Sleeping …”
Sleep 60

#Send out an email with the names
$emailFrom = “”
$emailTo = “”
$subject = “VMware_Tools_Updated & Machines Got Rebooted”
$smtpServer = “”

$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $Report)

My requirement is, i will add all 50 vm’s to deploy.csv and run the script. It should upgrade on the vm servers which require vm tools upgrade and give me output only upgraded servers names. And i need output which vm servers tool upgrade failed as-well.


You forgot for inspect the current state to see which need upgrades.
There is a property somewhere in the output of get-vm that tells you version status. Evaluate it.

Thanks. Let me have a look.