VMware

This Question is Answered

1 "correct" answer available (10 pts)
13 Replies Last post: Jul 7, 2009 1:22 AM by hharold  

Get-CDDrive posted: Jan 4, 2008 2:59 AM

Click to view ief's profile Enthusiast 28 posts since
Aug 19, 2005

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

Re: Get-CDDrive

1. Jan 4, 2008 6:04 AM in response to: ief
Click to view JPatten's profile Enthusiast 50 posts since
Oct 16, 2007
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 (https://server/mob)

Re: Get-CDDrive

2. Jan 4, 2008 7:27 AM in response to: ief
Click to view bshell's profile Enthusiast 22 posts since
Apr 7, 2005
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.

Re: Get-CDDrive

3. Jan 4, 2008 7:33 AM in response to: ief
Click to view halr9000's profile Master 814 posts since
Jun 7, 2007
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

Re: Get-CDDrive

5. Jan 4, 2008 9:09 AM in response to: ief
Click to view halr9000's profile Master 814 posts since
Jun 7, 2007
Excellent! Be sure to award points as you feel appropriate so that the community will see this as an answered question.

Re: Get-CDDrive

6. Jan 7, 2008 2:47 AM in response to: ief
Click to view Rajeev S's profile Hot Shot 193 posts since
Oct 27, 2006
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 :)

Re: Get-CDDrive

7. Apr 22, 2008 1:11 PM in response to: Rajeev S
Click to view astrolab's profile Enthusiast 70 posts since
Nov 21, 2007

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

Re: Get-CDDrive

8. Apr 22, 2008 3:59 PM in response to: astrolab
Click to view sepeck's profile Novice 13 posts since
Apr 7, 2008

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

http://blogs.vmware.com/vipowershell/2008/03/we-are-beta.html

Re: Get-CDDrive

9. Jul 3, 2009 7:59 AM in response to: halr9000
Click to view hharold's profile Hot Shot 147 posts since
Oct 18, 2004

halr9000 wrote:

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


Re: Get-CDDrive

10. Jul 3, 2009 12:04 PM in response to: hharold
Click to view LucD's profile Champion 2,431 posts since
Oct 31, 2005
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 } }

Re: Get-CDDrive

11. Jul 3, 2009 1:01 PM in response to: hharold
Click to view LucD's profile Champion 2,431 posts since
Oct 31, 2005
Sorry, duplicate post.

Re: Get-CDDrive

12. Jul 4, 2009 11:06 AM in response to: LucD
Click to view hharold's profile Hot Shot 147 posts since
Oct 18, 2004

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

Re: Get-CDDrive

13. Jul 7, 2009 1:32 AM in response to: LucD
Click to view hharold's profile Hot Shot 147 posts since
Oct 18, 2004
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

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities