By using the Get-CDdrive command, Is it possible to display the VM name the CDdrive is connected to?
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 ()
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.
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
Thanks that worked for me!
Excellent! Be sure to award points as you feel appropriate so that the community will see this as an answered question.
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
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
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
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
Sorry, duplicate post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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