VMware Cloud Community
mburutzis
Contributor
Contributor
Jump to solution

PowerCli - update vm tools hangs

Hi all,

I am using the following script to update my VMs Tools:

$vcserver = "server01"
Connect-VIServer -server 192.168.10.67
import-csv c:\1.csv | foreach {
   Get-VM $_.Name | Update-Tools -NoReboot -RunAsync
}
Disconnect-VIServer -Server 192.168.10.67

It works fine with Windows 2008 R2, but when I want to update Windows 2003 R2, it just hangs at "Initiated VMWare Tools Install or upgrade".  But when I go into the VM, the CD is not even mounted.

What am I doing wrong?

Reply
0 Kudos
1 Solution

Accepted Solutions
nielse
Expert
Expert
Jump to solution

Is there any information in the logs? It might happen that u get the error "TOOLS INSTALL Error copying upgrader binary into guest". If this is the case move or delete the following file: "C:\WINDOWS\Temp\VMwareToolsUpgrader.exe" and try again.

Does this provide additionial information or errors?

@nielsengelen - http://foonet.be - VCP4/5

View solution in original post

Reply
0 Kudos
16 Replies
xenot
Contributor
Contributor
Jump to solution

Where the tools running before? Are they still runing at the moment?

From which version are you upgrading to which?

Reply
0 Kudos
mburutzis
Contributor
Contributor
Jump to solution

Yes, they were running and still running...  We patched recently our ESXi hosts and want the tools to match the host version.  On the VM its 4.0.0 build-261974. The host is at 4.0.0 504850

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

Is there any information in the logs? It might happen that u get the error "TOOLS INSTALL Error copying upgrader binary into guest". If this is the case move or delete the following file: "C:\WINDOWS\Temp\VMwareToolsUpgrader.exe" and try again.

Does this provide additionial information or errors?

@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
mburutzis
Contributor
Contributor
Jump to solution

Worked like a charm.  Now, I have to integrate a function to check for the file and then delete the VMwareToolsUpgrader.exe.

Thanks again! Points awarded

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

No problem, you might want to check out the "Invoke-VMscript" function to determine if the file exists or not.

@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
mburutzis
Contributor
Contributor
Jump to solution

This will not work.  I do not have powershell on all my servers.  The problem is access to the C:\Windows\Temp folder in order to delete the exe file.  I can't seem to be able to access the file remotely and delete it.

anyways, lots of digging and testing to do...

thanks again

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Can't you use the hidden share \\servername\C$ to delete the file?

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can also start a BAT file with Invoke-VMScript.

If the VMware Tools are already installed, you can launch a 'del' command to all of them.


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

Reply
0 Kudos
mburutzis
Contributor
Contributor
Jump to solution

Do I need to have powershell within the VM I need to run a bat file?  Where would I need to put the bat file?

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

You can place the bat inside the VM. The VM doesn't need PowerShell. I suggest you lookup the function Invoke-VMScript (http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Invoke-VMScript.html).

You will have to refer to the path. There is an example on the page:

$script = '&"$env:ProgramFiles\Common Files\Microsoft Shared\MSInfo\msinfo32.exe" /report "$env:Tmp\inforeport"'

Invoke-VMScript -ScriptText $script -VM VM -HostCredential $hostCredential -GuestCredential $guestCredential
@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No need for PowerShell in the VM to execute a BAT script.

And you do not need the BAT file to be copied to the VM first.

On the ScriptText parameter you pass the BAT lines.

See the Invoke-VMScript cmdlet help.


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

mburutzis
Contributor
Contributor
Jump to solution

Awesome!! Exactly what I was looking for.  Her is what I got:

import-csv c:\1.csv | foreach {
   Get-VM $_.Name | Invoke-VMScript -ScriptType bat -ScriptText "del c:\Windows\temp\vminst.log" -RunAsync -GuestUser administrator -GuestPassword Password
   }

Is there a way to have a prompt for credentials and passing it to all VMs in the csv.  I tried removing GuestUser and Guest Password, but prompts at every server listed.

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

The following should work if your CSV looks somethings like:

vmname,guestuser,password

vm1,administrator,mycoolpass

vm2,administrator,mysecondpass

The following code should read your file and then connect to each VM with the correct username and password.
$vmlist = Import-CSV c:\1.csv
foreach ($item in $vmlist) {
    $vm = $item.vmname
    $username = $item.guestuser
    $password = $item.password
    Get-VM $vm | Invoke-VMScript -ScriptType bat -ScriptText "del c:\Windows\temp\vminst.log" -RunAsync -GuestUser $username -GuestPassword $password
}
@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
mburutzis
Contributor
Contributor
Jump to solution

I want to use one account (domain account with admin rights) and not have to put it in a file.  I want it to be available for multiple users from tech support.

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

I am confused by your question. Since you are using a domain account the password should be the same everywhere?

Or do you want a prompt which asks for the username and the password and then do something ?

If this is the case you can try something like this:

Connect-VIserver -server 192.168.10.67

$username = Read-Host "Enter username:"

$password = Read-Host "Enter password:"

Import-CSV c:\1.csv | foreach {
    Get-VM $_.Name | Invoke-VMScript -ScriptType bat -ScriptText "del  c:\Windows\temp\vminst.log" -RunAsync -GuestUser $username  -GuestPassword $password
}

@nielsengelen - http://foonet.be - VCP4/5
mburutzis
Contributor
Contributor
Jump to solution

exactly what I needed... I do have the tendency to vaguely express myself, but thanks for understanding.  You guys are the best!Smiley Wink

Reply
0 Kudos