VMware tools upgrade script modification

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Venkata Kalyan Venkata Kalyan 4 months, 3 weeks ago.

  • Author
    Posts
  • #46402
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    Hi,
    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.

    -Kalyan

  • #46405
    Profile photo of TomBaker
    TomBaker
    Participant

    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.

  • #47075
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    Thanks. Let me have a look.

    -Kalyan

You must be logged in to reply to this topic.