VMware Cloud Community
AGFlora
Enthusiast
Enthusiast
Jump to solution

Code to report vm's with cdrom set to connect at power on

this is what I have so far:

Get-VM | Sort | % {

$vm = $_

$out = "" | Select VmName, CdRomStatus, IsoFile

$out.VmName = $vm.Name

$vm.CDDrives | where {$_.ConnectionState.Connected -or $_.IsoPath -ne $null} | % {

$out.Connected = $_.ConnectionState.Connected

$out.IsoFile = $_.IsoPath

$report += $out

}

}

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
ctrople
Enthusiast
Enthusiast
Jump to solution

That should do it:

Get-VM | Sort | % {
$vm = $_
$out = "" | Select VmName, CdRomStatus, IsoFile, StartConnected
$out.VmName = $vm.Name
$cds = $vm.CDDrives
$vm.CDDrives | where {$_.ConnectionState.Connected -or $_.IsoPath -ne $null -or $_.StartConnected} | % {
$out.Connected = $_.ConnectionState.Connected
$out.IsoFile = $_.IsoPath
$out.StartConnected = $_.StartConnected
$report += $out
}
}

======================================

Chyna Trople, VCP

Monitor. Correlate. Act. | vWire.com

======================================

Chyna Trople, VCP Monitor. Correlate. Act. | vWire.com

View solution in original post

Reply
0 Kudos
4 Replies
ctrople
Enthusiast
Enthusiast
Jump to solution

That should do it:

Get-VM | Sort | % {
$vm = $_
$out = "" | Select VmName, CdRomStatus, IsoFile, StartConnected
$out.VmName = $vm.Name
$cds = $vm.CDDrives
$vm.CDDrives | where {$_.ConnectionState.Connected -or $_.IsoPath -ne $null -or $_.StartConnected} | % {
$out.Connected = $_.ConnectionState.Connected
$out.IsoFile = $_.IsoPath
$out.StartConnected = $_.StartConnected
$report += $out
}
}

======================================

Chyna Trople, VCP

Monitor. Correlate. Act. | vWire.com

======================================

Chyna Trople, VCP Monitor. Correlate. Act. | vWire.com
Reply
0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

Thanks fro your help.

It actually worked when I appended $._ConnectionState to .StartConnected

$_.ConnectionState.StartConnected

Reply
0 Kudos
ctrople
Enthusiast
Enthusiast
Jump to solution

Sorry for the oversight. Glad that worked!

======================================

Chyna Trople, VCP

Monitor. Correlate. Act. | vWire.com

======================================

Chyna Trople, VCP Monitor. Correlate. Act. | vWire.com
Reply
0 Kudos
AGFlora
Enthusiast
Enthusiast
Jump to solution

No problem...thanks again for your help.

Reply
0 Kudos