Skip to content
vJAL.nl
  • Partners
    • BDRSuite by Vembu
  • About me
  • Home
  • Search Icon
Configuring a VMware Tools Repository leveraging PowerCLI (6.7U1 and newer)

Configuring a VMware Tools Repository leveraging PowerCLI (6.7U1 and newer)

12 August 2020 Jesper Alberts Comments 0 Comment

Heads up: this script only functions with vSphere 6.7 Update 1 and newer

Ever since version 10.0 VMware has decoupled VMware Tools from vSphere releases. This gives you the opportunity to deploy images of ESXi without VMware Tools integrated, which saves you disk space and speeds up the deployment process.

Another benefit of this change is that you can now standardize your environment based on a single version by configuring a centralized repository, which gives you option to be in control of which version your environment is running with minimal effort.

In early 2019 VMware published a blog post on how to do this manually through the Managed Object Browser (MOB). However doing so is quite the task at it involves a lot of clicking for just one host, now try and do this for 20 ESXi hosts.

To make life easier I decided to create a PowerCLI script which loops all ESXi hosts for a given vCenter Server (you could add filters to only alter ESXi hosts with a specific property) and changes the directory for the “ProductLockerLocation” for said ESXi hosts.

Let’s take a look at the PowerCLI script step by step.

Table of Contents

  • Step 1
  • Step 2
  • Step 3
  • Step 4

Step 1

The first section is about connecting to vCenter using the information you’ll be prompted for upon running the script. You can safely alter this to provide the credentials in the script, use New-VICredentialStoreItem or save the credentials in an encrypted file.

    # Ask the user for the required information to connect to vCenter
    $vCenterServer = Read-Host "Enter the vCenter Server hostname"
    $AdminUsername = Read-Host ("Enter the username for the administrative account")
    $AdminPassword = Read-Host ("Password for " + $AdminUsername) -AsSecureString:$true
    $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $AdminUsername, $AdminPassword

    # Connect to the specified vCenter Server
    Connect-viserver -Server $vCenterServer -Credential $Credentials

Step 2

The second section is about getting the information required to actually start changing something. In my case I tend to use Get-VMHost to fetch all ESXi hosts and alter the configuration, but you’re free to add some sort of filter here.
The second action that takes place is that you’ll be prompted with an overview with the available datastores in the environment, of which you’re required to select the one on which you’ll upload the VMware Tools files.
Third and finally in this step is that you’ll be prompted to provide a name for the folder which will be created (if it’s not yet available). This is the folder in which you’ll have to place the VMware Tools files.

    # Specify different variables used in the script
    $ESXiHosts = Get-VMHost
    $DSName = (Get-Datastore | Out-GridView -PassThru).Name
    $DSFolder = Read-Host ("Enter the folder name for the VMware Tools Repository")
    $DSPath = "/vmfs/volumes/$DSName"
    $Location = "$DSPath/$DSFolder"

Step 3

After the second section the script will mount a PSDrive and check if the folder already exists. If it doesn’t exist, it will be created with the information specified in the previous part.
If it happens to already exist, the script will move to changing the actual configuration.

    # Start with testing if the directory exists, if not it will be created. Otherwise the VMware Tools location will be changed.
    Write-Output "Checking if the folder already exists on the datastore"
    $Datastore = Get-Datastore -Name "$DSName"
    New-PSDrive -Location $Datastore -Name DS -PSProvider VimDatastore -Root "\" | Out-Null
    $CheckPath = Test-Path "DS:\$DSFolder"

    If ($CheckPath -match "False") {
      Write-Output "The folder '$DSFolder' on datastore '$DSName' does not exist, creating it now."
      # Creating the folder on the datastore
      New-Item -Path "DS:\$DSFolder" -ItemType Directory | Out-Null
      #  Disconnects the earlier created PSDrive
      Remove-PSDrive -Name DS -Confirm:$false | Out-Null
    }

Step 4

Once everything is prepared we can now start changing the configuration itself.

    ForEach ($ESXiHost in $ESXiHosts) {
      $esx = Get-VMHost -Name $ESXiHost
      $OldLocation = $esx.ExtensionData.QueryProductLockerLocation()
      $esx.ExtensionData.UpdateProductLockerLocation($Location) | Out-Null
      Write-Output "Changed VMware Tools location on $ESXiHost from $OldLocation to $Location"
    }

After which the script will disconnect from vCenter and calls it a day.
The script is using a simple version of “try and catch”, which means it will stop at any error and calls it out in the console.

All you have to do now is upload the content of the VMware Tools package to the new location. The VM’s will automatically compare to this location now and show if they are up-to-date or not.

As with anything found on the internet, test it in a lab environment first!
The full code is available below to copy or to download as a .PS1 file.

Change_VMware_Tools_LocationDownload
 <#
.SYNOPSIS
    Change_VMware_Tools_Location.ps1 - PowerShell Script to change the VMware Tools location to a central one (like a datastore)
.DESCRIPTION
    This script is used to alter the default VMware Tools location to a central one (for all ESXi hosts).
    It will list a grid view of all datastores so you can select the one to use and prompts you for the name of the folder to create.
    The VMware Tools files itself will not be uploaded, this is a manual action.

    This script only works on vSphere 6.7 Update 1 and newer. Older versions require a different method for changing the VMware Tools location!
.OUTPUTS
    Results are printed to the console.
.NOTES
    Author        Jesper Alberts, Twitter: @jesperalberts, Blog: www.vjal.nl

    Change Log    V1.00, 12/03/2020 - Initial version
#>

$ErrorActionPreference = "Stop"

try {

    # Ask the user for the required information to connect to vCenter
    $vCenterServer = Read-Host "Enter the vCenter Server hostname"
    $AdminUsername = Read-Host ("Enter the username for the administrative account")
    $AdminPassword = Read-Host ("Password for " + $AdminUsername) -AsSecureString:$true
    $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $AdminUsername, $AdminPassword

    # Connect to the specified vCenter Server
    Connect-viserver -Server $vCenterServer -Credential $Credentials
    # Specify different variables used in the script
    $ESXiHosts = Get-VMHost
    $DSName = (Get-Datastore | Out-GridView -PassThru).Name
    $DSFolder = Read-Host ("Enter the folder name for the VMware Tools Repository")
    $DSPath = "/vmfs/volumes/$DSName"
    $Location = "$DSPath/$DSFolder"

    # Start with testing if the directory exists, if not it will be created. Otherwise the VMware Tools location will be changed.
    Write-Output "Checking if the folder already exists on the datastore"
    $Datastore = Get-Datastore -Name "$DSName"
    New-PSDrive -Location $Datastore -Name DS -PSProvider VimDatastore -Root "\" | Out-Null
    $CheckPath = Test-Path "DS:\$DSFolder"

    If ($CheckPath -match "False") {
      Write-Output "The folder '$DSFolder' on datastore '$DSName' does not exist, creating it now."
      # Creating the folder on the datastore
      New-Item -Path "DS:\$DSFolder" -ItemType Directory | Out-Null
      #  Disconnects the earlier created PSDrive
      Remove-PSDrive -Name DS -Confirm:$false | Out-Null
    }
    ForEach ($ESXiHost in $ESXiHosts) {
      $esx = Get-VMHost -Name $ESXiHost
      $OldLocation = $esx.ExtensionData.QueryProductLockerLocation()
      $esx.ExtensionData.UpdateProductLockerLocation($Location) | Out-Null
      Write-Output "Changed VMware Tools location on $ESXiHost from $OldLocation to $Location"
    }
    Disconnect-VIServer -Confirm:$False | Out-Null
  }
  catch {
    Write-Warning $Error[0]
  }

Please follow and like us:
Tweet

PowerCLI
PowerCLI, VMware Tools, VMware vSphere

Post navigation

PREVIOUS
My VMware VCAP7-DTM Design (3V0-752) exam experience (remotely proctored)
NEXT
My VMware VCAP6-DTM Deploy (3V0-653) experience

Leave a Reply Cancel reply

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

Let’s stay in touch!

Twitter
LinkedIn

Blog sponsors

Recent Posts

  • Introducing BDRSuite v5.5.0 [sponsored]
  • Vembu Backup for Endpoints [sponsored]
  • Renewing your NVIDIA licenses on the DLS appliance
Retweet on Twitter Jesper Alberts Retweeted
Avatar Age Roskam @ageroskam ·
18 Jan

Next up: How to create on-demand packages in App Volumes.💽🖥️

#AppVolumes #vExpert #ITQlife

https://ageroskam.nl/vmware/create-an-on-demand-packages-in-app-volumes/

Reply on Twitter 1615710041901776896 Retweet on Twitter 1615710041901776896 2 Like on Twitter 1615710041901776896 9 Twitter 1615710041901776896
Retweet on Twitter Jesper Alberts Retweeted
Avatar Age Roskam @ageroskam ·
18 Jan

Published Apps on Demand are here📢. I hope you are exited as I am, cause this changes everything!

#AppVolumes #vExpert #ITQlife

https://ageroskam.nl/vmware/configure-published-apps-on-demand-in-horizon/

Reply on Twitter 1615732206806208512 Retweet on Twitter 1615732206806208512 1 Like on Twitter 1615732206806208512 8 Twitter 1615732206806208512
Avatar Jesper Alberts @jesperalberts ·
16 Jan

Part two is now live of our video series about setting up Mobile Threat Defense in conjunction with @WorkspaceONE. Thanks for the collaboration @r33mi!

ITQ @ITQ

Watch our new How To #ITQonversations video with @jesperalberts and @r33mi.

In this second part, they will show you how you can leverage the integration between Mobile Threat Defense and WS1. Don't forget to (re)watch part 1!

https://youtu.be/lETCwNaoAMM

Reply on Twitter 1614989600304365572 Retweet on Twitter 1614989600304365572 3 Like on Twitter 1614989600304365572 7 Twitter 1614989600304365572
Retweet on Twitter Jesper Alberts Retweeted
Avatar Richard Kasius @mrkasius ·
16 Jan

@JeffUlatoski talks about the new feature of #VMware App Volumes, Published Apps on Demand.

https://youtu.be/6f4gGH1paTU

Reply on Twitter 1614923807164096512 Retweet on Twitter 1614923807164096512 1 Like on Twitter 1614923807164096512 2 Twitter 1614923807164096512
Avatar Jesper Alberts @jesperalberts ·
13 Jan

Horizon 2212 is here, bringing Horizon Published Apps on Demand! https://docs.vmware.com/en/VMware-Horizon/8-2212/rn/vmware-horizon-8-2212-release-notes/index.html

Reply on Twitter 1613842185031487490 Retweet on Twitter 1613842185031487490 6 Like on Twitter 1613842185031487490 14 Twitter 1613842185031487490
Load More

Archives

  • December 2022
  • October 2022
  • August 2022
  • July 2022
  • June 2022
  • March 2022
  • August 2021
  • January 2021
  • October 2020
  • August 2020

Categories

  • BCDR
  • Certification
  • Dynamic Environment Manager
  • Horizon
  • NVIDIA vGPU
  • Partners
  • Personal
  • PowerCLI
  • Secure Email Gateway
  • UAG
  • Uncategorized

Tags

Back-up BCDR Certificates Certification DEM Dynamic Environment Manager Horizon Identity Manager ITQ Job Licensing Microsoft 365 NVIDIA Personal PowerCLI Replication SEG SEGv2 SSL SSLLABS Troubleshooting True SSO UAG Upgrading VCAP VCIX Vembu vGPU VMware Tools VMware vSphere Workspace One Access
© 2023   All Rights Reserved.
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}