You can use the vSphere Automation SDK to work with content library features. For example, you can create a local content library on a datastore.

The following sample script illustrates how you can get the content library service and retrieve information about existing content libraries. You can then combine working with both the vCenter Server API and the vSphere Automation SDK, as well as their corresponding objects, to create a new content library on a specific datastore. Optionally, you can create an advanced function that lets you list all content libraries and their details.

Verify that you are connected to a vCenter Server system.

1

Connect to a vSphere Automation SDK server.

Connect-CisServer -Server cis3.example.com -User 'MyAdministratorUser' -Password 'MyPassword'
2

Get the service that works with local content libraries.

$contentLibrary = Get-CisService com.vmware.content.local_library
3

List the IDs of existing content libraries.

$contentLibrary.list()
4

Retrieve details of existing content libraries.

$clID = $contentLibrary.list() | Select -first 1
$contentLibrary.get($clID.Value)
5

Get a datastore on which to create the content library.

$datastoreID = (Get-Datastore | select -first 1).extensiondata.moref.value
6

Create a local content library on the existing datastore.

$createSpec = $contentLibrary.help.create.create_spec.Create() 
$createSpec.name = "New Content Library 2" 
$createSpec.description = "A new sample Content Library from PowerCLI"
$createSpec.type = "LOCAL"
$createSpec.publish_info.persist_json_enabled = $false
$createSpec.publish_info.published = $false
$createSpec.storage_backings = $contentLibrary.help.create.create_spec.storage_backings.Create() 
$storageSpec = $contentLibrary.help.create.create_spec.storage_backings.Element.Create()
$storageSpec.datastore_id = $datastoreID
$storageSpec.type = "DATASTORE"
$createSpec.storage_backings.Add($storageSpec) 
$uniqueID = [guid]::NewGuid().tostring()
$contentLibrary.create($uniqueID, $createSpec)
7

Create a PowerShell advanced function that lists all content libraries and their details.

Function Get-ContentLibrary ($name) {
    $contentLibrary = Get-CisService com.vmware.content.local_library
    $libraryIDs = $contentLibrary.list()
    Foreach ($library in $libraryIDs) {
        if ($name) {
            $contentLibrary.get($library.Value) | Where { $_.name -eq $Name } | Select Name, Type, Creation_Time, Last_Modified_Time, Storage_Backings
        } else {
            $contentLibrary.get($library.Value) | Select Name, Type, Creation_Time, Last_Modified_Time, Storage_Backings
        }
    }
}