Configure VMTools Repo

Need to update VMware Tools on your VMs?

There are lots of ways to do this but I like to use the built-in tools. If you use the built-in update checker, you need to have the latest version in the ESXi hosts tools repository. By default, this is baked into the host installed image in each host. This script will change that to a shared location on a datastore and folder of your choosing. 

Once again, we connect ot vCenter, like always. Then we get a list of datastores, and this is where it gets fancy! We display that list using Out-GridView -PassThru so you can make a selection and click OK. With the datastore selected, we get a list of top level folders and make a selection using the same Out-GridView -PassThru. With a path (hopefully) selected, we display the old path for kicks and update to the new path.

What makes this ugly?

$viServer = 'vcsa.contoso.com'


Connect-VIServer -Server $viServer

 

$vmHosts = Get-VMHost

$DSName = (Get-Datastore | Out-GridView -PassThru)

New-PSDrive -Name toolsDatastore -Location $DSName -PSProvider VimDatastore -Root '\' | Out-Null

$DSFolder = (Get-ChildItem -Path toolsDatastore: | Where-Object -Property ItemType -EQ Folder | Out-GridView -PassThru).name

Remove-PSDrive -Name toolsDatastore

$DSPath = "/vmfs/volumes/$DSName/$DSFolder"


ForEach ($vmHost in $vmHosts) {


    Write-Output "Updating from: $($vmHost.ExtensionData.QueryProductLockerLocation()) To: $DSPath"

    $vmHost.ExtensionData.UpdateProductLockerLocation($DSPath)


}