I was recently doing some work with the vSphere Content Library and I needed to extract some information using the Content Library API. I was hoping there were a few out of the box PowerCLI cmdlets but to my surprise, there was only one cmdlet called Get-ContentLibraryItem which did not get into the level of details that I was looking for, which was on a per-file level rather than item-level. I had also search the web to see if anyone had built any functions and although a few existed, none that did the very basics which was retrieving all libraries, library items and library item files.

Not having worked with the Content Library APIs before, I figure this would be a good learning opportunity and created a PowerCLI module called ContentLibrary.psm1 which contains the following functions:

  • Get-ContentLibrary
  • Get-ContentLibraryItems
  • Get-ContentLibraryItemFiles

Before you can make use of these functions, make sure to connect to the CIS endpoint of your vCenter Server using the Connect-CisServer cmdlet.

Here is a screenshot of the vSphere Web Client showing all available Content Libraries:


Here is an example of retrieving the same information using the following command:

Get-ContentLibrary


Note: You also have the ability to filter for the name of a specific Content Library by using the -LibraryName parameter

Here is a screenshot of the vSphere Web Client showing the individual Items within a Content Library:


Here is an example of retrieving the same information using the following command:

Get-ContentLibraryItems -LibraryName Test


Note: You also have the ability to filter for the name of a specific Content Library Item by using the -LibraryItemName parameter

Although the granularity when using the vSphere Web Client is at a Content Library Item, using the Content Library API, you can get additional information on the Item itself which is then composed of a set of files. The following command will allow you to retrieve all Files or you can use -LibraryItemName parameter to filter on a specific Item.

Get-ContentLibraryItemFiles -LibraryName Test -LibraryItemName TinyVM

6 thoughts on “vSphere Content Library PowerCLI community module

    • You didn’t read the blog post, did you? 😉 The singular is OOTB cmdlet which doesn’t give too much info, I’ve implemented my own set of functions, hence plural

  1. Is there anyway we can convert the item in content-lib directly to usual template instead of converting it to the VM and the template because we use cloud-stack for our internal cloud which will see only items in VMs and templates folders and not in the content-library ..

    • No, there is not. A VM Template in Content Library is completely different than a traditional VM Template and even the way it is stored differs. My suggestion is for the solution to integrate w/Content Library APIs directly, so you benefit from using CL 🙂 rather than limiting it to what traditional templates can do and not taking advantage of what CL provides

  2. William,

    I’m not sure if this is possible but, at my previous job, I had written a PowerCLI Script to take our templates once a month, convert them to VMs, install the latest windows updates, and then convert it back to template. I’d like to do something similar with the Content Library. I know the VM cannot be converted within the library, but are there cmdlets to export the VM from the library and download the OVA? From there I can script deploying the OVA into vCenter, installing the required updates, etc. I’d also need a way to delete the existing item in the Content Library and then import the new VM, replicate it, etc.

    Thoughts?

    Thanks!

    Ben Liebowitz

Thanks for the comment!