VMware Cloud Community
arnaudp
Contributor
Contributor

Get-CDDrive does not return any objects

Hello everyone,

I'm having a bug with the Get-CDDrive cmdlet which returns nothing at all. I'm using PowerShell v2, PowerCLI 4.0 U1 against ESXi 4.0 U1 and vCenter Server 4.0 U1.

I have the same result whether or not I connect to the ESXi directly.

PS > Get-VM | Get-CDDrive

Iso HostDevice RemoteDevice

--- -


-


Arnaud Petitjean

PowerShell MVP

http://powershell-scripting.com

0 Kudos
11 Replies
jeveenj
Enthusiast
Enthusiast

Hi Arnaud,

This might be happening because the device type of CD/DVD drive is “client device”.

Hope this helps.






-If you found this information useful, please consider awarding points for Correct or Helpful.

-If you found this information useful, please consider awarding points for Correct or Helpful.
0 Kudos
Budrumi
Contributor
Contributor

Have you resolved this? I'm having exactly the same issue. CD drive is using ISO, not "client device".

0 Kudos
RvdNieuwendijk
Leadership
Leadership

I have done some testing. First I thought that I had the same problem as you have. But then I found that the problem is, that the properties in the default Get-CDDrive output are empty. Try the next script and you will probably see your CD drives:

Get-VM | `
  ForEach-Object {
    $VM = $_
    Get-CDDrive -VM $VM | `
      Select-Object @{N="VM";E={$VM.Name}},Name,Isopath,HostDevice,RemoteDevice
  } | `
  Format-Table -AutoSize

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Budrumi
Contributor
Contributor

Thanks Robert, your script works.

Do you have any idea though why the default get-cddrives output is empty?

0 Kudos
LucD
Leadership
Leadership

The problem is caused by an error in the VMware.VimAutomation.Format.ps1xml file.

This file defines which properties are shown by default for a specific object.

For the VMware.VimAutomation.Client20.CDDriveImpl object it says to display the following properties by default

           <TableRowEntries>
               <TableRowEntry>
                  <TableColumnItems>
                     <TableColumnItem>
                        <PropertyName>Iso</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>HostDevice</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>RemoteDevice</PropertyName>
                     </TableColumnItem>
                  </TableColumnItems>
               </TableRowEntry>
            </TableRowEntries>

While the properties actually are called

   TypeName: VMware.VimAutomation.Client20.CDDriveImpl

Name            MemberType Definition
----            ---------- ----------
ConnectionState Property   VMware.VimAutomation.Types.ConnectInfo ConnectionState {get;}
HostDevice      Property   System.String HostDevice {get;}
Id              Property   System.String Id {get;}
IsoPath         Property   System.String IsoPath {get;}
Name            Property   System.String Name {get;}
ParentId        Property   System.String ParentId {get;}
RemoteDevice    Property   System.String RemoteDevice {get;}

As you can see the XML says Iso while the property is called IsoPath.

If you update the PS1XML file like below you will see the property

           <TableRowEntries>
               <TableRowEntry>
                  <TableColumnItems>
                     <TableColumnItem>
                        <PropertyName>IsoPath</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>HostDevice</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>RemoteDevice</PropertyName>
                     </TableColumnItem>
                  </TableColumnItems>
               </TableRowEntry>
            </TableRowEntries>

Or if you specify the properties explicitely (by name IsoPath or by selecting all the properties (*)), the property will display correctly as well.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RvdNieuwendijk
Leadership
Leadership

I think you will have to add the Name property for the VMware.VimAutomation.Client20.CDDriveImpl object to the .ps1xml file also. Then you will allways see that there is a CD drive device connected to the VM:

           <TableRowEntries>
               <TableRowEntry>
                  <TableColumnItems>
                     <TableColumnItem>
                        <PropertyName>Name</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>IsoPath</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>HostDevice</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>RemoteDevice</PropertyName>
                     </TableColumnItem>
                  </TableColumnItems>
               </TableRowEntry>
            </TableRowEntries>

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Budrumi
Contributor
Contributor

Thanks for the thorough explanation. I'll try "fix" the xml on my machine and hope this will be resolved in next PowerCLI release.

Cheers

0 Kudos
RvdNieuwendijk
Leadership
Leadership

I did the .PS1XML fix on my machine and will share what I did. First it is not a good idea to change the original VMware.VimAutomation.Format.PS1XML file because it has a digital signature. Therefore I created a new file called VMware.VimAutomation.CDDrive.Format.PS1XML and put that file in my $PSHOME directory, which on my computer is C:\Windows\System32\WindowsPowerShell\v1.0. The contents of the file is:

<?xml version="1.0" encoding="utf-8" ?>
<Configuration>
   <ViewDefinitions>
      <View>
         <Name>VirtualCDDrive</Name>
         <ViewSelectedBy>
            <TypeName>VMware.VimAutomation.Client20.CDDriveImpl</TypeName>
         </ViewSelectedBy>
         <TableControl>
            <TableHeaders>
               <TableColumnHeader>
                  <Label>Name</Label>
                  <Width>15</Width>
                  <Alignment>left</Alignment>
               </TableColumnHeader>
               <TableColumnHeader>
                  <Label>IsoPath</Label>
                  <Width>20</Width>
                  <Alignment>left</Alignment>
               </TableColumnHeader>
               <TableColumnHeader>
                  <Label>HostDevice</Label>
                  <Width>20</Width>
                  <Alignment>left</Alignment>
               </TableColumnHeader>
               <TableColumnHeader>
                  <Label>RemoteDevice</Label>
                  <Width>30</Width>
                  <Alignment>right</Alignment>
               </TableColumnHeader>
            </TableHeaders>
            <TableRowEntries>
               <TableRowEntry>
                  <TableColumnItems>
                     <TableColumnItem>
                        <PropertyName>Name</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>IsoPath</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>HostDevice</PropertyName>
                     </TableColumnItem>
                     <TableColumnItem>
                        <PropertyName>RemoteDevice</PropertyName>
                     </TableColumnItem>
                  </TableColumnItems>
               </TableRowEntry>
            </TableRowEntries>
         </TableControl>
      </View>
   </ViewDefinitions>
</Configuration>

To use the new VMware.VimAutomation.CDDrive.Format.PS1XML in your current PowerCLI session you have to give the command:

Update-FormatData -PrependPath $PSHOME\VMware.VimAutomation.CDDrive.Format.PS1XML

If you want to use the new .PS1XML file in all your PowerCLI sessions, you will have to add the next command to your PowerShell profile:

### Add changed CDDrive format
if (Get-PSSnapin | Where-Object {$_.Name -eq "VMware.VimAutomation.Core"}) {
  Update-FormatData -PrependPath $PSHOME\VMware.VimAutomation.CDDrive.Format.PS1XML
}

You can edit your PowerShell profile from within a PowerShell/PowerCLI session with:

notepad $PROFILE

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
yboychev
Hot Shot
Hot Shot

Hi all,

This is a bug in PowerCLI indeed. It is reported in our bug tracking system and will be resolved for one of the upcoming releases. Although it might bring some confusion to the users it does not severely affect automation and report generation as the property IsoPath is present and can be retrieved by calling $cdDrive.IsoPath as already some of you suggested. The workaround suggested for modifying CDDrive.Format.PS1file also sound good.

Thanks all for catching this for us!

\Yavor

0 Kudos
gopanaboena
Enthusiast
Enthusiast

Hi

Please try with this command

Get-CDDrive -VM *

0 Kudos
balarajugopinat
Enthusiast
Enthusiast

use this command

Get-VM -Name VM | Get-CDDrive

(make sure you have to  Connects to a vSphere server and retrieves the CD drive of the virtual machine named VM)

0 Kudos