VMware Cloud Community
StephenMoll
Expert
Expert

Advanced Settings and VM Templates

We are using advanced settings to store metadata about VMs in their respective VMX files.

The scripts use this metadata to control deployment actions, among which are actions to have some VMs converted to VM templates.

Unfortunately once converted to a template the metadata is no longer easily accessible.

Does anyone know of a way to access a key value pair from a VM template's VMTX file using PowerCLI?

Is there a way to manipulate key/value pairs in the VMTX file from PowerCLI?

0 Kudos
2 Replies
LucD
Leadership
Leadership

You can download the .vmtx file, and then just read it.

Something like this

$templateName = "MyTemplate"

$tgtFolder = 'C:\Temp'


Get-Template -Name $templateName | % {

   $dsName, $vmtxPath = $_.ExtensionData.Config.Files.VmPathName.Split()

   $dsName = $dsName.Trim('[]')

   $ds = Get-Datastore -Name $dsName


   New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null

   Copy-DatastoreItem -Item "DS:$vmtxPath" -Destination $tgtFolder

   Remove-PSDrive -Name DS -Confirm:$false

}


Get-ChildItem -Path $tgtFolder -Filter "*.vmtx" |

   Get-Content


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

0 Kudos
StephenMoll
Expert
Expert

That looks really useful LucD. I'll give it a whirl.

0 Kudos