VMware Cloud Community
vin01
Expert
Expert
Jump to solution

Unable to update vm tools with UpgradeTools_Task

Can some one correct me on the below code.

Issue:code is executing successfully but  UpgradeTools_Task running for long time with out any execution output like failed or success.

Is the argument which I am passing in the script is correct?

If not what argument should I pass for windows and non-windows server.

Note: When I run get-vm |Update-Tools -NoReboot  it succeeded on the same vm which is failed with the below code.

$allresourcepools = 'resp1' ,'resp2'

$respExpression = "^$($allresourcepools -join '$|^')$"

foreach($resourcepool in (Get-View -ViewType ResourcePool  -Filter @{'Name'=$respExpression})){

$vmsinresourcepool = Get-View -Id $resourcepool.Vm

$vmtoolsoutdate = $vmsinresourcepool|? {$_.guest.toolsversionstatus -eq "guestToolsNeedUpgrade"}

$vmexpression= "^$($vmtoolsoutdate.name -join '$|^')$"

$installerArgs = 'REBOOT="ReallySuppress"'

#'/S /v"/qn REBOOT=ReallySuppress"'

$vmtoolsupdate=Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmexpression}

%{($vmtoolsupdate).UpgradeTools_Task($installerArgs)}

}

Regards Vineeth.K
0 Kudos
28 Replies
LucD
Leadership
Leadership
Jump to solution

The command looks ok to me, in fact I tested and it seems to work.

Also the fact the you get an installation log seems to indicate that the command parameters were accepted.

On the reboot, you could try replacing "REBOOT=R" with "REBOOT=ReallySuppress" and adding the "/norestart" parameter.

But if one of the custom actions of the installer changes the REBOOT option, there is not a lot you can do I'm afraid.

Scan the installation log if the reboot is changed somewhere.

When you get the prompt with the setup.exe parameters, that indicates that the setup.exe noticed an error in the parameters.

Try displaying at the command that is sent to that station, there might be an error in there


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vin01
Expert
Expert
Jump to solution

Thanks for info. This is working for windows 2k8 without reboot.

$path="$($drive)\setup.exe /S /v ""/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"""

For win 2k12 is there any way to accept UAC.

I tried this in DOS prompt its asking for UAC after accepting its started installation.

D:\setup.exe /S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"

Regards Vineeth.K
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can enable/disable UAC from the command line, but it requires a reboot.

See for example Enable or Disable UAC From the Windows Command Line


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vin01
Expert
Expert
Jump to solution

Thanks Guru for your kind supportSmiley Happy Most of the issue is resolved.Based on this I will develop script as per client requirement and I will post here for future reference.

Regards Vineeth.K
0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Hi Vineeth,

Could you please post Final Code of Windows & Linux Code Separately, So that we can have a reference for it.

0 Kudos
vin01
Expert
Expert
Jump to solution

Hi LucD

This is the final script.I need few more corrections if possible.

1. I used try/catch method to try multiple passwords for login but here I can not get correct write output after succeeding the login attempt with correct password but tools installation is going as expected.

2.Can we avoid invoke cmd twice for disabling UAC and installing vmtools and sending them in one cmd.

Still any modifications required to improve faster execution process in the script please correct me.

Write-Host 'Fetching Resource Pools Info'

$allresourcepools = 'SEZ08'

$respExpression = "^$($allresourcepools -join '$|^')$"

foreach($resourcepool in (Get-View -ViewType ResourcePool  -Filter @{'Name'=$respExpression})){

Write-Host "Fetching VMs in $resourcepool"

$vmsinresourcepool = Get-View -Id $resourcepool.Vm

$vmtoolsoutdate = $vmsinresourcepool|? {$_.guest.ToolsRunningStatus -eq "guestToolsRunning" -and $_.guest.toolsversionstatus -eq "guestToolsNeedUpgrade"}

$vmexpression= "^$($vmtoolsoutdate.name -join '$|^')$"

$installerArgs = '/S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs,WYSE"'

$vmtoolsupdate=Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmexpression}

if($vmtoolsupdate.Guest.GuestFullName -contains "*Windows*"){

%{($vmtoolsupdate).UpgradeTools_Task($installerArgs)}

}

else{

%{($vmtoolsupdate).UpgradeTools_Task($null)}

}

Start-sleep -s 300

$tasklist=Get-Task |? {$_.Name -eq "UpgradeTools_Task" -and $_.State -eq "Error"}

$installfailedvms=Get-View -Id $tasklist.ObjectId -Property Name | select -ExpandProperty Name

$installfailedwin=Get-VM $installfailedvms |?{$_.ExtensionData.Guest.GuestFullName -like "*windows*"}

foreach($batchinstallvms in $installfailedwin){

if($batchinstallvms.ExtensionData.Runtime.ToolsInstallerMounted -eq $false){

Mount-Tools -VM $batchinstallvms

}

else{

}

$code = "wmic logicaldisk where drivetype=5 get deviceid, volumename, description"

$disableUAC= "C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f"

$found = $false

    try{

     $result1 = Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@1" -ScriptType Bat -ScriptText $code | Select -ExpandProperty ScriptOutPut

$result1 | where{$_ -match '(?<Drive>\w:)\s*VMware Tools'} | %{

    $drive = $Matches['Drive']

}

$path="$($drive)\setup.exe /S /v ""/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"""

Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@1" -ScriptType Bat -ScriptText $disableUAC | Select -ExpandProperty ScriptOutPut

$resultout1=Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@1" -ScriptType Bat -ScriptText $path | Select -ExpandProperty ScriptOutPut

      $found = $true

    }

  catch [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidGuestLogin]{

        $result1 = "Invalid logon"

      }       catch{

        $result1 = "any other output"

      }

      if(!$found){

           try{

     $result2 = Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@2" -ScriptType Bat -ScriptText $code | Select -ExpandProperty ScriptOutPut

$result2 | where{$_ -match '(?<Drive>\w:)\s*VMware Tools'} | %{

    $drive = $Matches['Drive']

}

$path="$($drive)\setup.exe /S /v ""/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"""

Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@1" -ScriptType Bat -ScriptText $disableUAC | Select -ExpandProperty ScriptOutPut

$resultout2=Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@2" -ScriptType Bat -ScriptText $path | Select -ExpandProperty ScriptOutPut

      $found = $true

    }

  catch [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidGuestLogin]{

        $result2 = "Invalid logon"

      }       catch{

        $result2 = "any other output"

      }

      if(!$found){

           try{

     $result3 = Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@2" -ScriptType Bat -ScriptText $code | Select -ExpandProperty ScriptOutPut

$result3 | where{$_ -match '(?<Drive>\w:)\s*VMware Tools'} | %{

    $drive = $Matches['Drive']

}

$path="$($drive)\setup.exe /S /v ""/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"""

Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@1" -ScriptType Bat -ScriptText $disableUAC | Select -ExpandProperty ScriptOutPut

$resultout3=Invoke-VMScript -VM $batchinstallvms -GuestUser "admin" -GuestPassword "admin@2" -ScriptType Bat -ScriptText $path | Select -ExpandProperty ScriptOutPut

      $found = $true

    }

  catch [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidGuestLogin]{

        $result3 = "Invalid logon"

      }       catch{

        $result3 = "any other output"

      }

      Write-Output "VM: $($batchinstallvms.Name): $found"

      Write-Output "VM: $($batchinstallvms.Name): $result1"

      Write-Output "VM: $($batchinstallvms.Name): $result2"

      Write-Output "VM: $($batchinstallvms.Name): $result3"

}

}

}

}

Regards Vineeth.K
0 Kudos
LucD
Leadership
Leadership
Jump to solution

On 2) you need to disable UAC and reboot, before you can install.

You could combine the install and the enable UAC + reboot in one command, so at least 2 Invokes I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
vin01
Expert
Expert
Jump to solution

‌ssure I'll share it once testing is done successfully.

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert
Jump to solution

‌ok thanks LucD. I will recheck the mentioned thing and get back to you.

Regards Vineeth.K
0 Kudos