PowerCLI

 View Only
  • 1.  VMWare Tools + HW Upgrade Combined w/reboot at end

    Posted Mar 31, 2025 05:18 PM

    @LucD You had helped me a few years back hoping I can capture your help before you leave the community.  

    Looking to combine this into 1 x fancy script to perform both tasks...  

    1. Grab VM names from a list.  
    2. Flip the HW upgrade bit to upgrade on next restart
    3. Tell the VM to upgrade tools and reboot
    4. Loop through 1 x VM at a time from the list

    I may have a completely botched script here that I combined so hoping you can assist.  

    Part 1 works great (tools upgrade).  I hadn't tested part 2 as of yet.  

    $HardwareUpdateVMs = get-vm (Get-Content d:\temp\VMtools_HW.txt) 
    
    
    Foreach ($VM in ($HardwareUpdateVMs)) {
    $VMConfig = Get-View -VIObject $VM.Name
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.ScheduledHardwareUpgradeInfo = New-Object -TypeName VMware.Vim.ScheduledHardwareUpgradeInfo
    $vmConfigSpec.ScheduledHardwareUpgradeInfo.UpgradePolicy = "always"
    $vmConfigSpec.ScheduledHardwareUpgradeInfo.VersionKey = "vmx-21"
    $VMConfig.ReconfigVM($vmConfigSpec)
    }
    
    
    
    Foreach ($VM in ($HardwareUpdateVMs)) {
    % { get-view $_.id } |
    Where-Object {$_.Guest.ToolsVersionStatus -like "guestToolsNeedUpgrade"} |
    select name, @{Name="ToolsVersion"; Expression={$_.config.tools.toolsversion}}, @{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}}|
    Update-Tools -NoReboot -VM {$_.Name} -Verbose
    }


  • 2.  RE: VMWare Tools + HW Upgrade Combined w/reboot at end

    Posted Apr 01, 2025 07:18 AM

    Hello Ed.

    Unfortunately I cannot help with the script but I would like to provide some insight.

    Upgrading a VM's hardware version is not recommended unless there is a specific new feature a VM requires.

    https://knowledge.broadcom.com/external/article/315390/upgrading-a-virtual-machine-to-the-lates.html#:~:text=VMware%20does%20not%20recommend%20upgrading,there%20are%20issues%20post%20upgrade.

    I see you have -NoReboot in the script.  I have been doing upgrade testing of the VMware Tools 12.5.1 version that just came out.  I have discovered that a reboot is mandatory.  We have versions 12.3.5 and up in our environment and they all have required a reboot.  I believe this is because:

    1. Support for the x86 version of VMware Tools has been deprecated.
    2. The combination and number of base hardware drivers being upgraded (NIC, Video, SCSI, etc.) require a reboot.

    Also, if you have to upgrade MS Visual C++ Redistributable, that also typically requires a reboot.

    I don't mean to rain on your parade; just hoping to save you some heartburn.

    Thanks.




  • 3.  RE: VMWare Tools + HW Upgrade Combined w/reboot at end

    Posted Apr 01, 2025 08:14 AM

    Thanks @hgdeloitte much appreciated!  I agree the HW upgrade portion on the VMs is a double edged sword.  

    I've been able to get these 3 x working together thus far.  I may comment out the HW portion though.  

    $VMs = Get-VM (Get-Content d:\temp\VMtools_HW.txt) 
    
    Foreach ($VM in ($VMs)) {
        $VMConfig = Get-View -VIObject $VM.Name
        $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
        $vmConfigSpec.ScheduledHardwareUpgradeInfo = New-Object -TypeName VMware.Vim.ScheduledHardwareUpgradeInfo
        $vmConfigSpec.ScheduledHardwareUpgradeInfo.UpgradePolicy = "always"
        $vmConfigSpec.ScheduledHardwareUpgradeInfo.VersionKey = "vmx-21"
        $VMConfig.ReconfigVM($vmConfigSpec)
    }
    
    
    Foreach ($VM in $VMs) {
        $vm = Get-VM -Name $vm
        Write-Host "Updating VMware Tools on $($vm.Name)"
        Update-Tools -VM $vm -Verbose
    }
    
    Foreach ($VM in $VMs) {
        Write-Host "Restarting Guest OS on $($vm.Name)"
        Restart-VMGuest -VM $vm -Confirm:$false -Verbose
    }