VMware Cloud Community
SubhashTIL
Contributor
Contributor
Jump to solution

Add a VM to Content Library using PowerCLI error

Hello,

I have been trying to upload a VM as a template in the Content Library using Powercli. I am using Stuart Yerdon "Add-TemplateToLibrary" module but its failing with below error.

Source website. How to add a VM to Content Library using PowerCLI - Notes of a scripter

vCenter version:  6.5

PowerCli version: 6.5 Release 1, Build 4624819

PowerCLI C:\> Add-TemplateToLibrary -LibraryName 'testcontentlib' -VMname 'TEST02' -LibItemName 'TEST Template' -Description 'Uploaded via API calls'

Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'Create'.

At C:\Scripts\Add-TemplateToLibrary.psm1:46 char:1

+ $createOvfTarget = $ContentLibraryOvfService.Help.create.target.Creat ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Create:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

The property 'library_id' cannot be found on this object. Verify that the property exists and can be set.

At C:\Scripts\Add-TemplateToLibrary.psm1:47 char:1

+ $createOvfTarget.library_id = $library_ID

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'Create'.

At C:\Scripts\Add-TemplateToLibrary.psm1:49 char:1

+ $createOvfSource = $ContentLibraryOvfService.Help.create.source.Creat ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Create:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

The property 'type' cannot be found on this object. Verify that the property exists and can be set.

At C:\Scripts\Add-TemplateToLibrary.psm1:50 char:1

+ $createOvfSource.type = ((Get-VM $VMname).ExtensionData.MoRef).Type

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

The property 'id' cannot be found on this object. Verify that the property exists and can be set.

At C:\Scripts\Add-TemplateToLibrary.psm1:51 char:1

+ $createOvfSource.id = ((Get-VM $VMname).ExtensionData.MoRef).Value

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'Create'.

At C:\Scripts\Add-TemplateToLibrary.psm1:53 char:1

+ $createOvfCreateSpec = $ContentLibraryOvfService.help.create.create_s ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (Create:String) [], RuntimeException

    + FullyQualifiedErrorId : MethodNotFound

The property 'name' cannot be found on this object. Verify that the property exists and can be set.

At C:\Scripts\Add-TemplateToLibrary.psm1:54 char:1

+ $createOvfCreateSpec.name = $LibItemName

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

The property 'description' cannot be found on this object. Verify that the property exists and can be set.

At C:\Scripts\Add-TemplateToLibrary.psm1:55 char:1

+ $createOvfCreateSpec.description = $Description

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

Creating Library Item --  TEST Template

A server error occurred: 'com.vmware.vapi.std.errors.invalid_argument': Unable to validate input to method com.vmware.vcenter.ovf.library_item.create (Server error id:

'vapi.invoke.input.invalid')Structure 'operation-input' is missing a field: create_spec (Server error id: 'vapi.data.structure.field.missing'). Check

$Error[0].Exception.ServerError for more details.

At C:\Scripts\Add-TemplateToLibrary.psm1:59 char:1

+ $libraryTemplateId = $ContentLibraryOvfService.create($UniqueChangeId ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], CisServerException

    + FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Types.V1.CisServerException

Thanks

Sub#

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Great!
It's always advised to try and keep your PowerCLI version up to date.


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

View solution in original post

6 Replies
scott28tt
VMware Employee
VMware Employee
Jump to solution

Moderator: Thread moved to the PowerCLI area.


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Without seeing your code, it is hard to determine what went wrong.

Is there any reason you are using such an old PowerCLI version?


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

Reply
0 Kudos
SubhashTIL
Contributor
Contributor
Jump to solution

Thanks, Lucd for the input. I will upgrade the powercli to version 6.7.

I have attached the code for your reference.

Sub#

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Why 6.7, PowerCLI is currently at version 12.1?


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

Reply
0 Kudos
SubhashTIL
Contributor
Contributor
Jump to solution

Hi Lucd,

Upgrading the Powercli version to 12.1.0 Build 17009493 helped. I am able to sucessfully upload the VM as a template in the content Library.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Great!
It's always advised to try and keep your PowerCLI version up to date.


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