PowerCLI: Upload to Content Library using PowerCLI

Summary:
Basically was looking to upload an iso or ovf from my system not using the web client to content library.  Couldn't find an example to upload from my local system only to have vCenter pull it from somewhere.

Details:
So I took VMware's example and added "PUSH" functionality to upload from my local system to the content library.  Learned some interesting things in the process.  Mainly related to OVF uploads.  The content library service, or possibly something else, parses the OVF looking for the related files.  Then the Content Library is instructed to essentially wait for those other files to be uploaded before it closes the upload task.  Kinda interesting.

Anyway, the script is powershell core based, so compatible across all platforms.

Links:

Comments

Impeeza said…
Hi, Thanks a lot for all your effort, I am trying to use the PS script using a $URL like:

$URL = 'ds:///vmfs/volumes/58d2f02a-a6f12fc4-718b-0025b5501006/ISOs/NewISOFileForContent.iso'

but I get a error:

A server error occurred: 'com.vmware.vapi.std.errors.internal_server_error': Provider method implementation threw unexpected exception:
com.vmware.vapi.std.errors.InternalServerError (Server error id: 'vapi.bindings.method.impl.unexpected'). Check $Error[0].Exception.ServerError for more details.
At line:111 char:1
+ $ContentLibraryUpdateItem.add($newSessionId,$createFileSpec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], CisServerException
+ FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Types.V1.CisServerException

File upload session is initiated.
A server error occurred: 'com.vmware.vapi.std.errors.not_allowed_in_current_state': No files have been added to the session. (Server error id:
'com.vmware.vdcs.cls-main.update_session_no_files'). Check $Error[0].Exception.ServerError for more details.
At line:158 char:1
+ $ContentLibraryUpdateSession.complete($newSessionId)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], CisServerException
+ FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Types.V1.CisServerException


the Item is created on the Content Library with 0 bytes

there is any I can change to be able to upload a ISO file to a Content Library from a datastore?

Again thanks a lot for your work.
Zsoldier said…
I never tried the pull methods, if I were to guess, it might be a problem w/ your URL format. Have you tried just two forward slashes instead of three like shown in the example?

Popular posts from this blog

NSX-T: vCenter and NSX-T Inventory out of Sync (Hosts in vSphere not showing up in NSX-T)

MacOS: AnyConnect VPN client was unable to successfully verify the IP forwarding table modifications.

vCenter: Cluster Skip Quickstart Workflow via API