imompero
Enthusiast
Enthusiast

Update Vmware tools on linux via Powercli...is it possible?

I have been looking all over the internet and havent' been real successful in finding a script that will let me update vmware tools on a linux VM.  I would like to be able to input a csv or txt file so I can specifically say which linux vms get updated.

Anyone have a script like this?  Thanks in advance

0 Kudos
7 Replies
LucD
Leadership
Leadership

You could use the Invoke-VMScript cmdlet with ScriptType set to bash.

That way you should be able to run the '' command inside the guest OS and update the VMware Tools.

Have a look at the Mass upgrade of VMware Tools in Linux guests post for a sample bash script you can use.


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

0 Kudos
imompero
Enthusiast
Enthusiast

Thanks this helped, but still having some issues, here is what I got.  I am running a mixed environment for now, some 4.0 and some 4.1. Shortly we will be going to 4.1 all around.  But in the meantime I would like a script that could upgrade vmware tools for all my linux vms, if possible.

my test bash script(VMware_Tools_script_test4_1) & VMwareTools-8.3.7-341836.tar are pushed to the /tmp/ directory.  Next I run the powershell script below:

*******Update-LinuxVM4_1.ps1***********

param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\linuxvm.csv" )
Import-Csv -Path $CsvFile | ForEach-Object {
    Get-VM $_.VM | Invoke-VMScript -HostCredential $hc -GuestCredential $gc -ScriptText "/tmp/VMware_Tools_script_test4_1" -ScriptType bash
}

*******Update-LinuxVM4_1.ps1***********

Now sometimes it works and other times it doesn't, but even when it is successful and vmware tools updates within the powershell i get the following output.

Invoke-VMScript : 5/19/2011 2:24:55 AM    Invoke-VMScript        Error occured
while executing script on guest OS in VM 'VMTEST'. Could not locate "Bash" scri
pt interpreter in any of the expected locations.
At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Update
-LinuxVM4_1.ps1:3 char:35
+     Get-VM $_.VM | Invoke-VMScript <<<<  -HostCredential $hc -GuestCredential
$gc -ScriptText "/tmp/VMware_Tools_script_test4_1" -ScriptType bash
    + CategoryInfo          : ResourceUnavailable: (VMTEST:VirtualMachineImpl)
    [Invoke-VMScript], VimException
    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptCore_ExeLoo
   kupFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

Any help is much appreciated, thanks

0 Kudos
LucD
Leadership
Leadership

Which Linux distribution are you using ?

The message seems to indicate that bash can not be started. Could it be that the path is missing a directory for the account ?


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

0 Kudos
imompero
Enthusiast
Enthusiast

I am trying this on Red Hat 5.5 64 bit, I am running as root:

This is the bash script:

#!/bin/bash
    cd /tmp
    gunzip VM*.gz
    tar -xvf VM*.tar
    rpm -e VMwareTools
    echo "Old VMwareTools removed" >> /tmp/vmware_tools_upgrade.log
    cd vmware-tools-distrib
    perl vmware-install.pl -d
    echo "Installing VMware Tools" >> /tmp/vmware_tools_upgrade.log
    vmware-config-tools.pl -d
    echo "vmware-config-tools.pl -d executed" >> /tmp/vmware_tools_upgrade.log
    service vmware-tools restart
    echo "vmware-tools restarted" >> /tmp/vmware_tools_upgrade.log
    service network restart
    echo "network restarted" >> /tmp/vmware_tools_upgrade.log
    service vmware-tools status >> /tmp/vmware_tools_upgrade.log
    echo "VMware Tools Finsihed" >> /tmp/vmware_tools_upgrade.log
    exit

This is the bash line that is in /etc/passwd for root:

root:x:0:0:root:/root:/bin/bash

0 Kudos
LucD
Leadership
Leadership

The 2nd part of the error message seems to indicate that the resource is unavailable.

Was the guest perhaps just rebooted ?

Can you try something simple with Invoke-VMScript on that guest ?

For example, just sending an 'ls' command (same guest, same credentials) not as a script but directly in the ScripText parameter.


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

0 Kudos
imompero
Enthusiast
Enthusiast

Actually I tried that and I had an issue again, so then I tried it from my vCenter server and it started working.  The ls and the vmware tools install.

My only other question is that my current script requires that the vmware tools tar file be on the server already.  Any way to script this without needing the tar on the local guest OS?

0 Kudos
daspug201110141
Contributor
Contributor

I found this thread as I was have the same error, but with the powershell interpreter rather than Bash.

You can use copy-vmguestfile to copy files to/from your VM's.


As it's VMware tools you are trying to install, you can use mount-tools, unmount-tools and update-tools for these operations.

The error you had above (about the interpreter), I found was caused by requesting the OS reboot the VM (via the script it was calling). Changing this to a PowerCLI command to perform the reboot resolved the issue.

0 Kudos