Automation

 View Only
Expand all | Collapse all

Unable to update vm tools with UpgradeTools_Task

  • 1.  Unable to update vm tools with UpgradeTools_Task

    Posted Aug 02, 2016 07:24 AM

    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)}

    }



  • 2.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 02, 2016 11:38 AM

    The script will only work for VMs that have a Windows guest OS (you're using MSI Installer arguments).

    For non-Windows VMs you should be able to leave out the installer arguments.

    You could check on the OS and take one of two options.

    But I'm not sure it will work like that for all Linux flavours



  • 3.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 02, 2016 12:18 PM

    Tested on one RHEL server as below it worked with out reboot.

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

    Should I pass any other argument to work without reboot on other than RHEL.

    But if we pass argument for win 2k12 its failing I don't know why its throwing this error

    Tried These 3 arug

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

    #'REBOOT="ReallySuppress"'

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

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


    Error: vix error code = 21009



  • 4.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 02, 2016 12:51 PM

    I suspect that might be the issue discussed in KB2129927

    Can you check if the symptoms are there?



  • 5.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 02, 2016 01:05 PM

    Thanks for Info LucD. I am aware of that KB but luck even after applying.

    Esxi Version is also 5.5 with update 3b.



  • 6.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 02, 2016 01:17 PM

    LucD.. Can you please help me on this script. I am trying to update the tools by this way where i am facing vix error.

    $username = '10.xx.xx.xx\admin'

    $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString

    $Credentials = New-Object System.Management.Automation.PSCredential `

         -ArgumentList $UserName, $SecurePassword

    $VM = 'SEZ08VVM-904'

    Get-vm $VM | Dismount-Tools -ErrorAction SilentlyContinue

    Get-vm $VM | Mount-Tools

    $RMsession = New-PSSession -ComputerName $VM -Credential $Credentials -Authentication Basic

    Invoke-Command -Session $RMSession -ScriptBlock {$CDRom = Get-WmiObject -class Win32_CDROMDrive | select Drive `

    | ForEach {$_.Drive}; $Subpath = '\setup.exe'; $ExecuteEXE = Join-Path -Path $CDRom -ChildPath $Subpath; start-process $executeEXE -ArgumentList '-s -v-qn ADDLOCAL=ALL REBOOT=R'}

    #Remove-PSSession *

    Error:



  • 7.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 02, 2016 06:33 PM

    The error message list a number of possible causes.

    Is PowerShell Remoting enabled on the target server?

    Does the following work?

    Enter-PSSession -ComputerName SEZ08VVM-904

    Did you run a 'winrm quickconfig' on the target server? Or have a GPO that does that?

    You could eventually use psexec to execute that command on the target server(s).



  • 8.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 10:29 AM

    Hi LucD

    There is some firewall block issue which is not allowing me to connect remote machines from my local PC.

    Can you please help me out to complete installation by invoke a batch file.

    with the below script I can query which is the Compact disk where vmtools are mounted from there i need to do silent installation by passing in that batch file.

    #driverquery

    #wmic logicaldisk get caption,providername,drivetype,volumename

    $script = @"

    wmic logicaldisk where drivetype=5 get deviceid, volumename, description

    "@

    $vm=Get-VM 'SEZ08VVM-904'

    Mount-Tools -VM $vm

    if(Get-VMguest -VM $vm)

    {

        $found = $false

        try{

          $out1 = Invoke-VMScript -VM $vm -GuestUser "administrator" -GuestPassword "password@1" ` -ScriptText $script -ScriptType bat -ErrorAction Stop |

              Select -ExpandProperty ScriptOutput

          $found = $true

        }

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

            $out1 = "Invalid logon"

          }

          catch{

            $out1 = "any other output"

          }

          if(!$found){

              try{

                $out2 = Invoke-VMScript -VM $vm -GuestUser "admin" -GuestPassword "" ` -ScriptText $script -ScriptType bat -ErrorAction Stop |

                    Select -ExpandProperty ScriptOutput

                $found = $true

              }

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

                $out2 = "Invalid logon"

              }

              catch{

                $out2 = "any other output"

              }

          }

          if(!$found){

              try{

                $out3 = Invoke-VMScript -VM $vm -GuestUser "administrator" -GuestPassword "password@123" `

                    -ScriptText $script -ScriptType bat -ErrorAction Stop |

                    Select -ExpandProperty ScriptOutput

                $found = $true

              }

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

                $out3 = "Invalid logon"

              }

              catch{

                $out3 = "any other output"

              }

          }

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

          Write-Output "VM: $($vm.Name): $out1"

          Write-Output "VM: $($vm.Name): $out2"

          Write-Output "VM: $($vm.Name): $out3"

    }

    Sample Output :



  • 9.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 11:06 AM

    If the Firewall is blocking you, how are you going to run that bat file over on the other station(s)?



  • 10.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 11:56 AM

    I am not sure:smileyconfused: but the batch query on the above script which i executed on the same machine it worked.

    when I try this below

    Enter-PSSession -ComputerName 192.168.1.1 -Credential (Get-Credential) -Authentication Basic

    Enter-PSSession : Connecting to remote server 192.168.1.1 failed with the following error message : WinRM cannot complete the operation. Verify that

    the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled

    and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same

    local subnet. For more information, see the about_Remote_Troubleshooting Help topic.

    At line:1 char:1

    + Enter-PSSession -ComputerName 192.168.1.1 -Credential (Get-Credenti ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidArgument: (192.168.1.1:String) [Enter-PSSession], PSRemotingTransportException

        + FullyQualifiedErrorId : CreateRemoteRunspaceFailed



  • 11.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 01:00 PM

    Well, if you can't get to the remote machine, one way or another, it will be difficult to execute anything on the remote machine.

    That's not a technical issue, but a policy issue in your environment imho.



  • 12.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 01:36 PM

    I am sorry that my explanation of the issue is not going in correct way. I will try to explain once again..

    Thanks Guru.I understood I can't get PS session on remote machine but I can execute a batch query with invoke method which i tried on the above script.

    Ex:

    $script = @" 

    wmic logicaldisk where drivetype=5 get deviceid, volumename, description 

    "@


    Here I required a help to complete this batch query.

    $script = @" 

    wmic logicaldisk where drivetype=5 get deviceid, volumename, description 

    "@


    with this I can get output of drive letter where vmtools are mounted inside the guest OS.

    so with this drive letter I need to proceed on silent installation with in the same .bat file.


    Like:

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


    so where I should add the drive letter on the above line for redirecting  to that setup for installation.



  • 13.  RE: Unable to update vm tools with UpgradeTools_Task
    Best Answer

    Posted Aug 03, 2016 04:48 PM

    Ok, got it (I think).

    You want to call the setup.exe via Invoke-VMScript, but you need the correct drive letter.

    Try something like this, it uses a RegEx expression to extract the drive letter.

    The command that is generated can be send to the VM via Invoke-VMScript to start the VMware Tools installation.

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

    $vm = Get-VM MyVM

    $result = Invoke-VMScript -VM $vm -ScriptType Bat -ScriptText $code | Select -ExpandProperty ScriptOutPut

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

        $drive = $Matches['Drive']

    }

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



  • 14.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 05:48 PM

    Thanks Guru:smileyhappy: That is what I am looking but once step pending after execution

    setup.exe process is running inside guest  but tools are not updating.

    Tried with setup64.exe also but no luck.

    Is this argument which i am passing is correct?

    setup64.exe /S /v ""/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs"""



  • 15.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 05:55 PM

    It could be a quote thing, I double some quotes in my sample script to have them appear in the resulting string.

    Isn't the vmware.log of the VM showing what command was actually transmitted?

    Another option, try to execute the command string on a test VM from a DOS box.



  • 16.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 03, 2016 06:02 PM

    ‌ok.ill give a try and get back to you.Thanks Guru for your kind support.



  • 17.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 07:34 AM

    Hi LucD

    Tested on couple of windows machines(2k8 & 2k12) but  setup process was not stating in the guest OS but if I try this cmd inside the machine its working 'E:\setup.exe /S /v "/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs" (This is the output of our script)

    VMware logs are showing error something like this

    2016-08-04T07:13:37.685Z| vcpu-0| I120: CDROM ide1:0: CMD 0xad (*UNKNOWN (0xad)*) FAILED (key 0x5 asc 0x24 ascq 0)

    other than no errors found related to this in vmware.log



  • 18.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 08:08 AM

    Even Tested as below but still setup is not starting. I am still trying.Is any correction needed in the script ?

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

    $vm = Get-VM 'testvmtools'

    Mount-Tools -VM $vm

    $result = Invoke-VMScript -VM $vm -GuestUser "administrator" -GuestPassword "Admin@123" -ScriptType Bat -ScriptText $code | Select -ExpandProperty ScriptOutPut

    $result | 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 $vm -GuestUser "administrator" -GuestPassword "Admin@123" -ScriptType Bat -ScriptText $path | Select -ExpandProperty ScriptOutPut



  • 19.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 09:31 AM

    Try producing a log by changing the line like this

    $path="$($drive)\setup.exe /S /v ""/qn /l*v C:\Temp\vmt.log REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs""" 

    On the target VM there should be a log created (C:\Temp\vmt.log), perhaps that might explain what is happening.



  • 20.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 10:55 AM

    Yes this worked:smileyhappy:

    I am really sorry for this...I have done a silly mistake:smileysilly: after viewing the logs its showing there is no enough space in c drive for the installation.

    But one step is showing problem

    Tested on 2k8 -- Installation is success but its rebooting the server (Is there any mistake in the argument which I am passing)

    For 2k12 -- Invoke cmd taken long time and in taskmgr i am able to view setup.exe running is logs its showing as below..

    2016-08-02 07:05:50| BootStrapper-build-1734305| DisplayMessageBox: "VMware Product Installation" - "Usage:

       /? :  Show this dialog.

       /a :  Perform an administrative install.

       /a <full path to existing administrative install> :  Patch an existing administrative install.

       /s :  Hide initialization dialog. For silent mode use /s /v/qn.

       /v :  Parameters to pass to installer

       /c :  Clean out installation registration information

       /l :  Perform a detailed logging.

       /l <fullpath to log file> :  Perform a detailed logging."

    Can you please correct the argument to pass silent installation on for all windows os.



  • 21.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 11:12 AM

    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



  • 22.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 12:13 PM

    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"



  • 23.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 12:32 PM

    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



  • 24.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 04, 2016 03:03 PM

    Thanks Guru for your kind support:smileyhappy: 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.



  • 25.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 05, 2016 04:25 AM

    Hi Vineeth,

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



  • 26.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 05, 2016 02:13 PM

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



  • 27.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 05, 2016 10:59 AM

    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"

    }

    }

    }

    }



  • 28.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 05, 2016 01:55 PM

    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.



  • 29.  RE: Unable to update vm tools with UpgradeTools_Task

    Posted Aug 05, 2016 02:18 PM

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