Nov 05

Automate VMware Tools Shared Product Locker Configuration (Script)

In collaboration with my official (corporate) blog post on VMware Tools 10 deployment, I created a script that, if you take care of the pre-reqs, will save you OODLES OF TIME! and yes, I did just say oodles! Take a look through the official blog post before continuing, otherwise the script might not make too much sense.

What this script will do is it will:

  • Query all Shared Datastores in vCenter and present them to you in a dynamic menu to select the datastore where you have placed VMware Tools
  • Present all folders in the datastore to you in a dynamic menu to select the folder where you have placed VMware Tools
  • Check to make sure it sees both folder and verify that there are files in these folders (it doesn’t validate anything about the files, just that files are present)
  • If it sees something wrong it will stop the script and ask you to fix it
  • Prompt user if they want the script to automatically set the UserVars.ProductLockerLocation on all hosts that can see that shared Datastore
  • Prompt user if they want the script to automatically update the symlinks on each of these hosts
    • if yes, it will enable SSH on each host (it keeps track of any host that already had SSH enabled so it doesn’t DISABLE it at the end)
    • Run remote SSH commands via Plink.exe to remove the old Symlink and add the new one
    • if SSH was not running before this script was used, it will turn SSH off of those hosts
  • Congratulate you on saving yourself a ton of time.

Also, note that as you are going through this script, there are a number of things I have done to do additional checking of settings, additional messages, and additional if/then’s. Generally I refrain from doing so many in a script but for those who are newer to PowerCLI it tends to be somewhat easier to understand.

The script assumes that you have downloaded Plink.exe to a folder on your PowerCLI machine, that you have placed all the VMware Tools files into a shared datastore, your PowerCLI machine has DNS setup to where it can resolve each ESXi host that you’ll be dealing with, and that you have a PowerCLI session open and connected to vCenter. If you meet these pre-reqs then carry-on!

Raw Code (also on Github with link at bottom of post)


Choose the shared datastore where you placed the VMware Tools folders:


Select the folder from the shared datastore where you placed the VMware Tools folders


Decide if you want the script to do the UserVars setup for you

Set UserVars

Decide if you want the script to setup the SymLink for you


Securely (Mike Foley you’d be proud 😉 ) place ESXi credentials. This assumes all ESXi hosts have the same credentials, if that is not the case, you will need to modify the PowerCLI script.

esxi host auth

SSH is enabled on all hosts that are being updated and Remote SSH commands are executed

SSH is disabled on any host where it was already turned off prior to running the script.


I found it would take me (and I’ve done it a lot manually by now) about 2 1/2 minutes per host to do this manually. Judging by the time it takes me, I added a nice little “you save roughly x time” to the end, based on how long it would take me, and the number of hosts.. It’s safe to assume that time saved because of fat-fingering and human error would be roughly 4 minutes/host… so anyways, just remember Automation ROCKS!

You can find this script on Github HERE


Skip to comment form

  1. Jason R

    Note that line 78 should have “ans2” and not “ans”, like this:
    $selection2 = $menu2.Item($ans2)

    Also, those who copy and paste the script might find that HTML entities break the script. Be sure to replace the <, > and & entities with their correct symbols before running it.

    Otherwise, the script appears to have worked perfectly! Thanks!

    1. Brian Graf

      Thanks Jason,
      I fixed it on the Github page as well as in the post.
      Great catch!

  2. Michael Stols

    Great script, however I ran into this issue using plink:
    The server’s host key is not cached in the registry. You have no guarantee that the server is the computer you think it is. The server’s rsa2 key fingerprint is: ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx If you trust this host, enter “y” to add the key to PuTTY’s cache and carry on connecting. If you want to carry on connecting just once, without adding the key to the cache, enter “n”. If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n)

    The solution is given here:

    I’ve added this line above the other plink commands:
    echo y | ./plink.exe -ssh $_.Name -l $Username -pw $PW exit

    It still gives errors, but only on the line I’ve added. It now executes the other two plink lines without errors.

  3. Joshua Post

    This script is a great help. VMware didn’t do a very good job of explaining what to do with the new version of tools.

    This script does not appear to handle datastore names with space in them. Of course, my selected datastore does, so I had to replace the line with the datastore name with plink with the specific name of my datastore and include some quotes. Any hope of revising this script to handle spaces? I tried but didn’t get anywhere

    Echo Y | ./plink.exe $_.Name -pw $PW -l $username “ln -s /vmfs/volumes/””Datastore name with Spaces””/VMware-Tools /productLocker”

  4. Brian J

    Does this work on vsphere 6? When I ran this in a test environment vsphere 6 I get the error below.

    Call “VirtualMachine.MountToolsInstaller” for object “vm” on vCenter Server “vcenter” failed.
    vix error code = 21001
    An unknown error has occurred.

    I tried to reboot the hosts and no luck.

    UserVars.ProductLockerLocation shows the correct path.

    Did the symlinks change from 5.5 to 6.x?

    1. Brian J

      Figured out my problem. I renamed the windows.iso to the tools version. Uploaded new version of tools to the datastore and all works fine. Thank you for the script!

      1. Brian Graf

        Glad you found it helpful! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

ten − 6 =