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?
You can download the .vmtx file, and then just read it.
Something like this
$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
That looks really useful LucD. I'll give it a whirl.