General

What’s New for Content Library Management

Welcome to the new year from the PowerCLI team! The first blog of the year is to look at some of the improvements to the way we manage one of the hidden gems of vSphere, Content Library. Little known fact, Content Library was one of the very first services in vCenter which was offered through a REST API as part of the vSphere 6.0 release! Since then, there’s been numerous updates and improvements to the Content Library. These updates have been discussed in the following blog by my teammate Nigel Hickey: The Evolution of Content Library

Late last year, we released PowerCLI 11.5. This new version included quite a few updates and number of new cmdlets to manage things like vCenter Alarms, VMware Cloud on AWS, and Content Library.

The new cmdlets for Content Library management are as follows:

  • New-ContentLibraryItem
  • Set-ContentLibraryItem
  • Remove-ContentLibraryItem
  • Export-ContentLibraryItem
  • New-ContentLibrary
  • Set-ContentLibrary
  • Get-ContentLibrary
  • Remove-ContentLibrary

As part of a tandem blog post with Nigel, we’re going to walk through interacting with a Content Library. Nigel will handle the tasks from the vSphere Client side over on the vSphere blog post “Creating and Using Content Library” and I’ll be showing how to do those same tasks with the new PowerCLI cmdlets here!

Creating a Local Content Library

First things first, in order to manage a Content Library, we need to create one. Luckily, one of the new cmdlets turns this process from roughly a 10-line process into, essentially, a one-liner!

The key pieces of information we need to make note of prior to creating a new local Content Library by running the New-ContentLibrary cmdlet:

  • Name
  • Description (optional, but recommended)
  • Whether publishing should be enabled
  • Datastore location

For my environment, I can use the following code to create a new local Content Library:

Demo: Creating a Content Library

Adding Items to Content Library

A Content Library can be used to store and share a number of things. From VMs to templates, scripts to certificates, we can import and make use of these items from any vCenter which has access. The first item we’ll be adding to our new Content Library is going to be a PowerShell script, which is small and simple to import.

For this task, we will want to identify a script to import and get familiar with the new cmdlet, New-ContentLibraryItem. This cmdlet has a couple parameters we will need to populate:

  • ContentLibrary: the Content Library we are looking to interact with
  • Files: the file/s to be imported to the Content Library
  • Name: the name of the item displayed in the Content Library

I’ll be referencing a script from one of the last PowerCLI blogs, Get-TriggeredAlarms.ps1, which I have stored in a local git repository.

We can use the following code to create a new Content Library item by importing our PowerCLI script:

Sample: Import Content Library Item

Exporting Items from Content Library

We have created a Content Library and imported our first item. The next step would be to use that item. There’s no native way to run, or even modify, our imported script, so we will want to export the script so we can run it from our local PowerShell session. In order to do this, we will use another new cmdlet named Export-ContentLibraryItem

There are two main parameters we will need to use for this task:

  • ContentLibraryItem: the item we’re looking to export
  • Destination: this is the location of where the item should be downloaded and stored to

We can use the following code to export our script from the Content Library:

Sample: Export Content Library Item

Remove Item from Content Library

For our last task, we’re going to complete the lifecycle of a Content Library item by removing our PowerCLI script. In order to accomplish this task, PowerCLI has another new cmdlet which can simplify this task to a single line by using Remove-ContentLibraryItem

There’s only one parameter we need to be concerned with, and that is the following:

  • ContentLibraryItem: this is the item we’re looking to remove

We can use the following code to remove our script from the Content Library:

Sample: Remove Content Library Item

Summary

Content Library is one of those vSphere features with so much untapped potential. This blog post took a look at how the release of PowerCLI 11.5 can streamline the management of a Content Library and the entire lifecycle of those items it contains.

Let us know in the comments how you’re using PowerCLI to automate the Content Library!

More information about PowerCLI 11.5’s release: New Release – PowerCLI 11.5.0
More information about performing these tasks in the vSphere Client: Creating and Using Content Library

Comments

21 comments have been added so far

  1. Are you looking for the optimum yet affordable SEO Packages? Don’t go beyond Jeewangarg.com, we have designed our SEO Packages in Delhi to match your economy as well as to get ranking on SERP.

  2. Plan a visit to Chardham as this yatra will take you to another world of beautiful landscapes with dense mountain forests, large valleys, waterfalls, flowing rivers etc. Arrow Aircraft provides Chardham Yatra by Helicopter. Get the best Chardham Helicopter Booking Price by Arrow AirCraft.

  3. There is still a big in New-ContentLibraryItem, I dont see a way to specify the file type. Example if I upload an ISO file, it is unmount able to a VM because the type is “file” , the web API has a parameter called type but just not the PowerCLI. I would be happy to help code this but I’m unsure as to where to begin.

  4. Thanks you so much for being my wife. there is nothing more than wishing a wife a happy wedding anniversary. thus I came up with this new colllection of anniversary messages that you can share with your life partener.

  5. I was recently tasked with migrating hundreds of ISO files from NFS to leverage the new content library functionalities, so naturally I turned to Powershell. I noticed that all of the ISOs were uploading as filetype “file” as opposed to filetype “Iso”. This is a big problem, because Isos can’t be mounted to a machine in VCenter without them being recognized as filetype “Iso”.

    I ended up fixing the problem by manipulating the VCenter database directly (which I do not recommend under normal circumstances), however, a parameter to set the filetype while uploading with Powershell would have saved me a lot of time and a big headache. Is this a feature that could be added? Or is there a safer way to fix this problem?

  6. Hey, Kylle Ruddy, Thanks for sharing this amazing post. At first, I was a little confused about removing the item from the content library. But your blog has cleared all my doubt. I learnt a couple of new and interesting things I didn’t know about. You must have spent hours in the research! Great Job, Kylle 🙂

  7. I really appreciate you for publishing this blog here about what’s new content library; it’s really a helpful and very useful for us. This is really appreciated that you have presented this data over here, I love all the information shared. Great article!Do check out this Flightdigital.co.nz, it has some great and nice ideas to look for.

Leave a Reply

Your email address will not be published. Required fields are marked *