HI all,
I have a VM template in one of the NFS datastores attached to my ESX host.
I need to get the Display name and some other details from the vmtx file of that template.
Any method to get values from vmtx file using PowerCLI..?
Thanks in advace for any help.
Hello, MattGeorgey-
One way you could do this would be to use the Copy-DatastoreItem cmdlet to grab the .vmtx file, and then you can read it, Get-Content on it, etc., as you please. Something like:
## copy the VMTX file from the datastore to a local spot
Copy-DatastoreItem vmstore:\MyDatacenterName\my_datastore_name\myTemplate\myTemplate.vmtx C:\temp\.
## get the contents of the VMTX file
$colVMTXContents = gc C:\Temp\myTemplate.vmtx
## get the line that contains the "displayName" value
$colVMTXContents | Select-String displayName
And, you can get to some of the items that are specified in the .vmtx file via the Config.ExtraConfig property of the View of the template object, like:
## get the template object
$tmplMyTemplate = Get-Template myTemplate
## get a particular value for an ExtraConfig item
$tmplMyTemplate.ExtensionData.Config.ExtraConfig | ?{$_.Key -eq "nvram"}
How does that do?
Hello, MattGeorgey-
One way you could do this would be to use the Copy-DatastoreItem cmdlet to grab the .vmtx file, and then you can read it, Get-Content on it, etc., as you please. Something like:
## copy the VMTX file from the datastore to a local spot
Copy-DatastoreItem vmstore:\MyDatacenterName\my_datastore_name\myTemplate\myTemplate.vmtx C:\temp\.
## get the contents of the VMTX file
$colVMTXContents = gc C:\Temp\myTemplate.vmtx
## get the line that contains the "displayName" value
$colVMTXContents | Select-String displayName
And, you can get to some of the items that are specified in the .vmtx file via the Config.ExtraConfig property of the View of the template object, like:
## get the template object
$tmplMyTemplate = Get-Template myTemplate
## get a particular value for an ExtraConfig item
$tmplMyTemplate.ExtensionData.Config.ExtraConfig | ?{$_.Key -eq "nvram"}
How does that do?
Thanks for the reply.
I wanted the "display-name" from the config file, but the second method doesnt lists that property.
But first method worked.