How to Mount a Content Library ISO on a VM

While Content Libraries are becoming more and more used, there are still some features that are not yet implemented in PowerCLI. So is it for example not possible to mount an ISO file located in a Content Library on a VM. The Set-CDDrive cmdlet is currently lacking this functionality, while the Web Client offers this option.

Like often, and one of the VMware PowerCLI features I absolutely like, when a cmdlet is missing a feature, you can fall back on the API to solve the issue.

Introduction

Like so often, the reason I had a closer look at this issue was due to a question in PowerCLI Community on VMTN.

My first step in such cases is always to have a look at the vSphere Web Services API.

But unfortunately, the ReconfigVM_Task method documentation didn’t make me any wiser. There is apparently no object, property, or method to mount an ISO from a Content Library onto a VM.

In the next step I had a look at the vSphere REST API Reference. But in there I could also not find anything specific about Content Library ISOs and VM CD drives.

When all else fails, look at the code!

And with Code Capture we have just that option!

The first thing I noticed while looking at the generated code, there are no ‘special’ object, properties, or method used. Just a plain ReconfigVM_Task call with an edit action on the CD drive device.

The only special feature was the value in the FileName property.

That value definitely pointed to the ISO file in the Content Library. At first I tried to compose that value by hand/script. But it turned out that some parts of the value were not obtainable via normal ways.

I found out then when I use the vimdatastore provider, the returned FullDatastorePath contained exactly the value I neededd.

The Code

Annotations

Line 34-37: The parameters that the function requires are objects returned by the Get-CDDrive and Get-ContentLibraryItem cmdlets. The function does not implement OBN support.

Line 40-41: This provides meaningful content for the message returned when the WhatIf switch is used.

Line 44-46: To avoid conflicts with PSDrives the user might already have defined, the function generates a 3-letter, random string that will be used as the drivename.

Line 52-53: To avoid a situation where the same ISO file might be uploaded to two different Content Libraries, the function first finds the path to the folder that corresponds with the requested Content Library.

Line 54-55: This search finds the actual path to the desired ISO file.

Line 60-72: A ‘regular’ call to the ReconfigVM_Task method.

Line 74: The function returns the CDDrive object, just like the regular Set-CDDrive cmdlet does. But since there is currently not yet support for ISO files from a Content Library, the filepath looks like a regular path to an ISO file. The Web Client does show that this is an ISO from a Content Library.

Sample Run

Using the function is rather straightforward.

The Web Client shows that an ISO from a Content Library is loaded.

Enjoy!

5 Comments

    Lucas

    OK, I figured out the backing issues, there were multiple ISOs of the same name in some different folders. After cleaning those up I can get most of the script to work and now it’s working and I even got it to flow through a foreach array.

    Lucas

    Have you had any issues trying to run this on vSphere 7.0.3g? I keep getting errors with the property ‘Backing’ not being found, or the subsequent ‘filename’ after that.

      LucD

      Strange.
      Can you post the complete error message you are getting?

        Lucas

        Here’s the error, I get it running against one machine or multiple:
        The property ‘Backing’ cannot be found on this object. Verify that the property exists and can be set.
        At line:55 char:1
        + $dev.Backing = New-Object VMware.Vim.VirtualCdromIsoBackingInfo
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound

        The property ‘FileName’ cannot be found on this object. Verify that the property exists and can be set.
        At line:56 char:1
        + $dev.Backing.FileName = $isoPath
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound

        The property ‘Connected’ cannot be found on this object. Verify that the property exists and can be set.
        At line:58 char:1
        + $change.Device.Connectable.Connected = $true
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : PropertyNotFound

        You cannot call a method on a null-valued expression.
        At line:60 char:1
        + $vm.ExtensionData.ReconfigVM($spec)
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Abul Ahmed

    Thanks heaps. makes some of tasks so easy.

Leave a Reply

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

*
*

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