11 Replies Latest reply on Oct 6, 2015 3:51 PM by balarajugopinath Branched from an earlier discussion.

    Get-CDDrive does not return any objects

    arnaudp Novice

      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

        • 1. Re: Get-CDDrive does not return any objects
          jeveenj Hot Shot

          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.

          • 2. Re: Get-CDDrive does not return any objects
            Budrumi Novice

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

            • 3. Re: Get-CDDrive does not return any objects
              RvdNieuwendijk Virtuoso
              User ModeratorsvExpert

              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

              • 4. Re: Get-CDDrive does not return any objects
                Budrumi Novice

                Thanks Robert, your script works.

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

                • 5. Re: Get-CDDrive does not return any objects
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Get-CDDrive does not return any objects
                    RvdNieuwendijk Virtuoso
                    User ModeratorsvExpert

                    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>
                    

                     

                    • 7. Re: Get-CDDrive does not return any objects
                      Budrumi Novice

                      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

                      • 8. Re: Get-CDDrive does not return any objects
                        RvdNieuwendijk Virtuoso
                        vExpertUser Moderators

                        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
                        

                         

                        • 9. Re: Get-CDDrive does not return any objects
                          yboychev Hot Shot
                          VMware Employees

                          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

                          • 10. Re: Get-CDDrive does not return any objects
                            gopanaboena Enthusiast

                            Hi

                             

                            Please try with this command

                             

                            Get-CDDrive -VM *

                            • 11. Re: Get-CDDrive does not return any objects
                              balarajugopinath 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)