PowerCLI

 View Only
  • 1.  upgrade vm hardware and tools with one script

    Posted Aug 15, 2014 08:47 PM

    hi Is it possible to upgrade vm hardware and tools with one script?

    I guess the vm would need to be shutdown before vm hardware upgrade and vmware tools will need to be upgraded before vm hardware.

    I think the logic is

    upgrade the tools while the guest is running.

    Do not reboot

    wait til the task is done then shutdown the guest

    check the status on the guest to see if its shutdown

    upgrade vm hardware

    then start up guest



  • 2.  RE: upgrade vm hardware and tools with one script

    Posted Aug 16, 2014 08:20 PM

    Try something like this

    foreach($vm in Get-VM){

        if($vm.ExtensionData.Guest){

            if($vm.Guest.State -eq "running"){

                if($vm.Guest.ExtensionData.ToolsStatus -eq "toolsOld"){

                    Update-Tools -VM $vm -NoReboot | Out-Null

                    while($vm.ExtensionData.Guest.ToolsStatus -eq "toolsOld"){

                        sleep 5

                        $vm.ExtensionData.UpdateViewData("Guest.ToolsStatus")

                    }

                    Shutdown-VMGuest -VM $vm

                    while($vm.ExtensionData.Runtime.PowerState -eq "poweredOn"){

                        sleep 5

                        $vm.ExtensionData.UpdateViewData("Runtime.PowerState")

                    }

                    if($vm.Version -ne "v10"){

                        Set-VM -VM $vm -Version v10 -Confirm:$false

                    }

                    Start-VM -VM $vm -Confirm:$false

                }

                else{

                    "$($vm.Name) Tools up to date"

                    if($vm.Version -ne "v10"){

                        Shutdown-VMGuest -VM $vm

                        while($vm.ExtensionData.Runtime.PowerState -eq "poweredOn"){

                            sleep 5

                            $vm.ExtensionData.UpdateViewData("Runtime.PowerState")

                        }

                        Set-VM -VM $vm -Version v10 -Confirm:$false

                    }

                    Start-VM -VM $vm -Confirm:$false

                }

            }

            "$($vm.Name) appears to have no Tools installed"

        }

    }



  • 3.  RE: upgrade vm hardware and tools with one script

    Posted Aug 17, 2014 06:02 PM

    Thanks Luc,

    I will give it a try. I assume this ill only work for windows guest vms and not linux right?



  • 4.  RE: upgrade vm hardware and tools with one script

    Posted Aug 17, 2014 08:01 PM

    The script doesn't use any Windows specific features, so this should work for *nix as well.



  • 5.  RE: upgrade vm hardware and tools with one script

    Posted Oct 17, 2014 04:32 AM

    LucD,

      Does this require VM's re-boot after running the script ?

    thanks

    vm2014



  • 6.  RE: upgrade vm hardware and tools with one script

    Posted Oct 18, 2014 06:40 PM

    Yes, that is what the Start-VM is doing.



  • 7.  RE: upgrade vm hardware and tools with one script

    Posted Nov 14, 2014 10:47 PM

    Hi LucD,

         Can this script be modified so that VMware tools installed without re-boot or silently so that during schedule windows the VM will re-boot ? I want VMware tools upgrade with no re-boot.

    thanks

    vm2014



  • 8.  RE: upgrade vm hardware and tools with one script

    Posted Nov 14, 2014 11:34 PM

    You can use the NoReboot switch on the Update-Tools cmdlet