Upload ISO to Content Library with PowerCLI and REST API

At work, there was a requirement to upload an ISO to the vSphere Content Library in an automated fashion (no GUI).

With PowerCLI 11, New-ContentLibrary commandlet seemed to do the job and creates and uploads the ISO file.

However, it creates and uploads the file as type: ‘file’

As you can see below type=’file’

If the item is of type ‘file’, it can’t be mounted to VMs (CD Drive)

Also, there is no option to change the type of the file with the PowerCLI Content Library commandlets.

Therefore, I used a combination of PowerCLI (to upload) and REST API (to modify the type), as below:

Modify the variables to match your environment.

What the script does:

  • Stores information (vcenter, item, location)
  • Gets credentials
  • connects to vcenter
  • Creates and uploads the iso file
  • creates an authorized session to REST API
  • uses Patch to modify the Content Library Item ID type field to ‘ISO’

You may also like

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.