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
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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"""


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

View solution in original post

28 Replies
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
vin01
Expert
Expert
Jump to solution

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

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

I suspect that might be the issue discussed in KB2129927

Can you check if the symptoms are there?


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

0 Kudos
vin01
Expert
Expert
Jump to solution

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

Esxi Version is also 5.5 with update 3b.

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

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:

powershellinvokeerror.JPG

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

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


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

0 Kudos
vin01
Expert
Expert
Jump to solution

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 :

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

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


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

0 Kudos
vin01
Expert
Expert
Jump to solution

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

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

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.


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

0 Kudos
vin01
Expert
Expert
Jump to solution

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.

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

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"""


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

vin01
Expert
Expert
Jump to solution

Thanks GuruSmiley Happy 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"""

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

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.


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

0 Kudos
vin01
Expert
Expert
Jump to solution

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

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

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

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

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

Regards Vineeth.K
LucD
Leadership
Leadership
Jump to solution

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.


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

vin01
Expert
Expert
Jump to solution

Yes this workedSmiley Happy

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.

Regards Vineeth.K
0 Kudos