thomps01
Enthusiast
Enthusiast

Basic commands to identify all virtual machines with connected CDROMS

Jump to solution

Hi all,


I'm totally new to PowerCLI but need to identity the simplest and shortest way for me to list all the virtual machines in my vCenter server that currently have a CDdrive attached.


I though I'd be able to achieve this with get-vm | get-CDDrive but no results are shown.

I've seen plenty of examples on the web of how people want to disconnect all drives in one hit, but initially I only want to identify them for a report.

Can this be achieved in a one liner?


Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this

Get-VM  | where {$_.cddrives} | Select Name, @{N="Connected";E={(get-CDDrive -VM $_).ConnectionState}}

or if you only want to see the ones that are connected, you could do this

Get-VM  | where {$_.cddrives} | Select Name, @{N="Connected";E={(get-CDDrive -VM $_).ConnectionState.Connected}} | where {$_.Connected}


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

Yes

Get-VM | where {$_.CDDrives} | Select Name


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

0 Kudos
thomps01
Enthusiast
Enthusiast

This is close to what I want.


At least it lists all of my virtual machines which actually contain a CDROM but it doesn't identify which have the CDROM in a connected state.

0 Kudos
LucD
Leadership
Leadership

Try something like this

Get-VM  | where {$_.cddrives} | Select Name, @{N="Connected";E={(get-CDDrive -VM $_).ConnectionState}}

or if you only want to see the ones that are connected, you could do this

Get-VM  | where {$_.cddrives} | Select Name, @{N="Connected";E={(get-CDDrive -VM $_).ConnectionState.Connected}} | where {$_.Connected}


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

View solution in original post

0 Kudos