VMware Cloud Community
zenivox
Hot Shot
Hot Shot
Jump to solution

Update a Content Library VM template using a local template

Hello, we have vcenter server 7.0.3. I'm trying to automate the update of a Content Library VM template using a local template. I see there is no PowerCLI cmd-let to accomplish this task, so I have used  the vCenter code capture and I got this:

#---------------list---------------
$_this = Get-CisService 'com.vmware.vcenter.ovf.export_flag'
$_this.list()

#---------------update---------------
$library_item_id = 'd7582caa-4dc1-4968-b4b6-e1893e42ef40'
$update_spec = @{}
$update_spec.name = '[redacted]'
$update_spec.description = ''
$_this = Get-CisService 'com.vmware.content.library.item'
$_this.update($library_item_id, $update_spec)
 
when run in command line what it does is simply a refresh of the content library item itself. Nowhere the local template is mentioned as a source. I believe the capture is not complete, it's missing the link between the 'list' phase and the 'update'. Or the com.vmware.content.library.item is only used to update name and description of the content library template. Anyone has the complete code?? I have PowerCLI 12.x and the Content Library sinchs with other libraries in various locations, so I would need to possibility to update the template in the library and not create a new one each time. Else the synch in place with the other libraries will break.
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Provided you are referring to an OVF & OVA Template, you could do

$clName = 'clLib'
$clItemName = 'MyTemplate'
$templateName = 'NewTemplate'

$cl = Get-ContentLibrary -Name $clName
$template = Get-Template -Name $templateName

Get-ContentLibraryItem -ContentLibrary $cl -Name $clItemName |
Set-ContentLibraryItem -Template Template1


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Provided you are referring to an OVF & OVA Template, you could do

$clName = 'clLib'
$clItemName = 'MyTemplate'
$templateName = 'NewTemplate'

$cl = Get-ContentLibrary -Name $clName
$template = Get-Template -Name $templateName

Get-ContentLibraryItem -ContentLibrary $cl -Name $clItemName |
Set-ContentLibraryItem -Template Template1


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

0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

ehi Luc, many thanks!

yes, in my case it's about OVF format. But frankly, any solution that allows me to update the CL template without deleting it and creating new one will do. If you say that the template format is better fine.. I can change it and will update the code that automates VMs deployment in all sites.

However, running your code I get:

 

 

Set-ContentLibraryItem : A parameter cannot be found that matches parameter name 'Template'.
At line:8 char:87
+ ... rary $cl -Name $clItemName | Set-ContentLibraryItem -Template $templa ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ContentLibraryItem], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.ContentLibrary.SetContentLibraryItem

 

in fact a get-help to the commands tells me that the parameter template does not exist. I have PowerCLI 12.1.0 build 17009493

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That parameter was introduced in PowerCLI 12.2.
We are currently at PowerCLI 13.0, perhaps you should consider an upgrade


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

0 Kudos
zenivox
Hot Shot
Hot Shot
Jump to solution

...and yes!! Habemus cmd-let for that 😁 Thanks Luc as usual! If you pass by Rome you have a carbonara paid!

0 Kudos