How to add and remove an ISO with VMware PowerCli (PowerShell)


Here another quick post about a PowerCli cmdlet.

First, you must be aware that the New-CDDrive and the Remove-CDDrive cmdlet are just to add and remove the “physically virtual” device.

On the other hand, you add(=load) and remove(=unload) an ISO file with the Set-CDDrive cmdlet, and we are using this cmdlet in the current post.

To connect an ISO to your VM

First, you have to find the path to your ISO file.
Please note that the path is case sensitive!
Use the Get-ChildItemcmdlet associated to the vmstore provider.

Get-ChildItem -Path vmstore:\

Once you found the file, display all properties with the Format-List cmdlet.

Get-ChildItem -Path vmstore:\DataCenterName\DataStoreName\SubfolderName\file.iso | Format-List

Watch out for a property named DatastoreFullPath. This is the relative path you will provide to the cmdlet in order to connect an ISO file.
Now you can connect the ISO file with the Set-CDDrive cmdlet.

Get-VM -Name Computer1 | Get-CDDrive| Set-CDDrive -Connected $true -IsoPath '[DataStoreName] SubfolderName\file.iso'

If you want, you can also configure the ISO file to be connected when the VM is starting.

Get-VM -Name Computer1 | Get-CDDrive| Set-CDDrive -Connected $true -IsoPath '[DataStoreName] SubfolderName\file.iso' -StartConnected $true

To disconnect an ISO from your VM

Get-VM -Name Computer1 | Get-CDDrive| Set-CDDrive -Connected $false

The ISO file is still “registered” in the drive’s settings but the VM’s guest operating system doesn’t see any CD/DVD anymore.

To remove an ISO from your VM

Please note that the VM must be powered off for the cmdlet to succeed.

Get-VM -Name Computer1 | Get-CDDrive| Set-CDDrive -NoMedia

Connect the VMware tools ISO file

This can be done with the Set-CDDrive cmdlet.

Get-VM -Name Computer1 | Get-CDDrive| Set-CDDrive -Connected $true -IsoPath '[] /usr/lib/vmware/isoimages/windows.iso'

However, there is a dedicated cmdlet to achieve this:

Get-VM -Name Computer1 | Mount-Tools

And to disconnect the WMware tools ISO file there is another dedicated cmdlet:

Get-VM -Name Computer1 | Dismount-Tools

What’s interesting with these two cmdlets is that, when you have already connected another ISO file, the VMware tools ISO file overlays the current ISO file, which you get back when you dismount the VMware tools ISO file.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s