VMware Cloud Community
ief
Contributor
Contributor

Get-CDDrive

By using the Get-CDdrive command, Is it possible to display the VM name the CDdrive is connected to?

blog www.ivobeerens.nl
0 Kudos
13 Replies
JPatten
Enthusiast
Enthusiast

The Get-CDDrive will only return information when given a VM, Template, or SnapShot, so I think we will need more clarification on what you are looking for. Just issuing the Get-CDDrive command without any parameters does not return any results.

However, if you do a Get-VM | Get-CDDrive, you will want to look at the ID line. It should say something like "VirtualMachine-##/3000". The "##" will contain the ID number of the VM that the Drive is connected to. I am not sure if you can get that number from powershell, but I checked it using the VI API and the number (##) does correspond to the VM id number on my box. You can also find the ID number by using the MOB of your host server ()

bshell
Enthusiast
Enthusiast

I added a feature request for something like this. If it is urgent I can help with a quick sript that will output a custom object.

0 Kudos
halr9000
Commander
Commander

Here's an example of how you can combine data from two cmdlets using calculated properties.

54# Get-VM pa* | ft name,@{label="ISOPath"; Expr = { ($_ | get-cddrive).ISOPath } }

Name ISOPath

-


-


patch2003x64

patch2003r2x64

patchvistaent_Vista Enterprise

patchxpx64sp1

patch2003sp1x64

patch2003sp2x64ie7 [] /vmimages/tools-isoimages/windows.iso

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
ief
Contributor
Contributor

Thanks that worked for me!

blog www.ivobeerens.nl
0 Kudos
halr9000
Commander
Commander

Excellent! Be sure to award points as you feel appropriate so that the community will see this as an answered question.

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Rajeev_S
Expert
Expert

Hi,

If you are trying to disconnect the CD-drive from the connected VM's. You can do it by using the below commands

$d = Get-VM

$cd = Get-CDDrive -VM $d

Set-CDDrive -CD $cd -Connected 0 -StartConnected 0

You have to connect to the VC first.

Hope this helps Smiley Happy

0 Kudos
astrolab
Contributor
Contributor

So is it possible to incorporate all in a .ps1 script that will first connect to VC and then diconnect the CD-ROMs such as:

get-VC vcserver.FQDN | get-cddrive | ? { $_.ConnectionState.Connected -eq "true" } |

Set-CDDrive -Connected:$false -Confirm:$false

0 Kudos
sepeck
Contributor
Contributor

Borrowing from another post and the example in the VMWare blog beta announcement

get-viserver vcserver.FQDN # provide your credentials when prompted | Get-VM | Get-CDDrive | ? { $_.ConnectionState.Connected -eq "true" } | Set-CDDrive -Connected:$false -Confirm:$false

0 Kudos
hharold
Enthusiast
Enthusiast

Get-VM pa* | ft name,@{label="ISOPath"; Expr = { ($_ | get-cddrive).ISOPath } }

Nice one indeed, but..... how can I get this output ONLY for VM's that have connected media?

Regards,

Harold

0 Kudos
LucD
Leadership
Leadership

Try this. It should also work for guests that more than 1 CD/DVD drive

 
Get-VM | where {$_.cddrives | %{$_.IsoPath -ne $null}} | ft name,@{label="ISOPath"; Expr = { ($_ | get-cddrive).ISOPath } }


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

0 Kudos
LucD
Leadership
Leadership

Sorry, duplicate post.


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

0 Kudos
hharold
Enthusiast
Enthusiast

Thanks man!

I am still learning, and I can learn a lot from oneliners like this one !

I will try this one monday at the office.

Thanks again,

Harold

0 Kudos
hharold
Enthusiast
Enthusiast

Hi Luc,

Brilliant!

This does exactly what I was looking for.

Thank you so much!

Just one question, if I run your query on the PS command-line, it output is perfect!

But when I put it in a .ps1 script and run it it from the same PS Command line it throws this error at me:

out-lineoutput : Object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not legal or not in the correct

sequence. This is likely caused by a user-specified "format-table" command which is conflicting with the default formatting.

Any idea?

Thanks again.

Regards,

Harold

0 Kudos