VMware Cloud Community
DennieTidwell
Enthusiast
Enthusiast

A script that detects cdroms that are connected or marked connect at power on and are mapped to non-shared storage

A script that detects cdroms that are connected or marked connect at power on and are mapped to non-shared storage.

This statement defines the VMs at risk for CDRom states that "block or may block if powered on" vMotion in HA or DRS.

The scripts below have been used to ID these risks but none match the statement perfectly and allow direct forwarding to VM Admins for correction of true risk.

Some ID all connected CDRoms, but if connected to shared storage there is no issue.

Some ID .ISO mappings but ignore connection state or when "connect on power on" is selected or not; or whether CDRom is connected; or if other non-shared storage is mapped.

So we need a script that lists "cdroms that are connected or marked connect at power on and are mapped to non-shared storage".

Any help appreciated and all points will be awarded.

+++++++

Get-VM | Where-Object {$_ | Get-CDDrive | Where-Object {$_.ConnectionState.Connected}} | select name, host, guest

+++++++
get-vm | where { $_ | get-cddrive | where { $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISOPath";Expression={( Get-CDDrive $_).isopath }} | ft –AutoSize

+++++++

HealthCheck 6.15 plugin

# Start of Settings
# VMs with CD drives not to report on
$CDFloppyConnectedOK ="APP*"
# End of Settings

$Result = @($FullVM | ?{$_.runtime.powerState -eq "PoweredOn" -And $_.Name -notmatch $CDFloppyConnectedOK} | ?{$_.config.hardware.device | ?{$_ -is [VMware.Vim.VirtualCdrom] -And $_.connectable.connected}} | Select Name)
$Result

$Title = "CD-Roms Connected"
$Header =  "VM: CD-ROM Connected - vMotion Violation: $(@($Result).Count)"
$Comments = "The following VMs have a CD-ROM connected, this may cause issues if this machine needs to be migrated to a different host"
$Display = "Table"
$Author = "Alan Renouf, Frederic Martin"
$PluginVersion = 1.2
$PluginCategory = "vSphere"

+++++++

#########################################################################################
# The script lists information about CD-ROM, Floppy, Parallel Ports and Seriel Ports    #
#                                   #
# Created by: Anders Mikkelsen, 2009                                  #
#########################################################################################
Add-PSSnapin VMware.VimAutomation.Core

$server = "VIServerName or IP"
$user = "UserName"
$pwd = "Password"

Connect-VIServer $server -User $user -Password $pwd

$vms = Get-VM
write "VM's with CD-ROM 'Connected' :"
foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.ConnectionState.Connected -eq "true"}}) {
write $vm.name
}
write "`nVM's with CD-ROM set to 'Connect at power on' :"
foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.ConnectionState.StartConnected -eq "true"}}) {
write $vm.name
}

write "`nVM's with CD-ROM device type set to 'Client Device' :"
foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.RemoteDevice.Length -ge 0}}) {
write $vm.name
}

write "`nVM's with CD-ROM device type set to 'Datastore ISO file' :"
foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.ISOPath -like "*.ISO*"}}) {
write $vm.name
}

write "`nVM's with Floppy 'Connected' :"
foreach ($vm in $vms | where { $_ | Get-FloppyDrive | where { $_.ConnectionState.Connected -eq "true"}}) {
write $vm.name
}

write "`nVM's with Floppy 'Connect at power on' :"
foreach ($vm in $vms | where { $_ | Get-FloppyDrive | where { $_.ConnectionState.StartConnected -eq "true"}}) {
write $vm.name
}

write "`nVM's with Floppy device type set to 'Client Device' :"
foreach ($vm in $vms | where { $_ | Get-FloppyDrive | where { $_.RemoteDevice.Length -ge 0}}) {
write $vm.name
}

write "`nVM's with Floppy device type set to 'Use excisting floppy image in datastore' :"
foreach ($vm in $vms | where { $_ | Get-FloppyDrive | where { $_.FloppyImagePath -like "*.FLP*"}}) {
write $vm.name
}

write "`nVM's with Serial Ports attached :"
$vms | Get-View | %{
  foreach($dev in $_.Config.Hardware.Device){
    if($dev.DeviceInfo.Label -like "Serial Port*"){
   foreach($tmp in $dev.Connectable){
     write $_.Name
     #write $tmp
   }
    }
  }
}

write "`nVM's with Parallel Ports attached :"
$vms | Get-View | %{
  foreach($dev in $_.Config.Hardware.Device){
    if($dev.DeviceInfo.Label -like "Parallel Port*"){
   foreach($tmp in $dev.Connectable){
     write $_.Name
     #write $tmp
   }
    }
  }
}

Tags (3)
0 Kudos
21 Replies
DennieTidwell
Enthusiast
Enthusiast

Thanks Hal of Hal Rottenberg's TFM

$Name = "*"
$vmCol = Get-VM -Name $Name
$Output = @()
foreach ($vm in $vmCol) {
    $vm | Get-CDDrive | ForEach-Object {
        $process = "" | select Name, DriveType, Connected, StartConnected
        $process.Name = $vm.Name
  switch ( $_ ) {
            { $_.IsoPath }        { $process.DriveType = "Datastore ISO

File" }
            { $_.HostDevice }    { $process.DriveType = "Host Device" }
            default                { $process.DriveType = "Client Device

" }
        }
        $process.Connected = $_.ConnectionState.Connected
  $process.StartConnected =

$_.ConnectionState.StartConnected
  $Output += $process
 
}
}
$Output | Export-Csv $filelocation -NoTypeInformation


"Name","DriveType","Connected","StartConnected"

"lllllllllll","Datastore ISO File","True","False"
"vvvvvvvvv","Datastore ISO File","True","True"

"nnnnn1","Client Device ","False","True"
"ggggggggggv","Datastore ISO File","False","False"
"ssssssssv","Datastore ISO File","False","False"
"xxxxxxxxxpv","Datastore ISO File","False","False"
"qqqqqqqqq","Client Device ","False","False"
"yyyyyyyyyy","Client Device ","False","False"
"uuuuuuuuu","Host Device","False","True"
"oooooooooooo","Datastore ISO File","True","True"
"vvvvvvvvv","Datastore ISO File","True","True"
"eeeeeeeeee","Datastore ISO File","False","False"
"nnnnnnnnnnn","Client Device ","False","False"


And so, the top two outputs are target filters but with the DS ISO File being a local Host folder (ie. vmimages folder with vmtools isos). If the VM is connected to a shared LUN ISO, it is not a vMotion problem or HA issue; and therefore, should not be on a problem report. The StartConnected config is an issue because the VM may power up under automatic conditions ie Web Servers in pools and then become a vMotion problem or HA issue.

So how do I get from this output to automated report with the VM names of Connected OR StartConnected AND DS ISO to unshared/local host ISOs?

Whew.

0 Kudos
DennieTidwell
Enthusiast
Enthusiast

My desire to provide a "ready to forward" report continues.

The Hal Rottenberg script with a small modification provides all output required. My problem continues to be providing a filtered report that contains only pertinent information without manual filtering.

Output desired (specifically those VMs at risk of not vMotioning or Reregistering during HA)

VM Name, DriveType, Connected, StartConnected, ISOPath

filtered to contain:

Are Connected = true or StartConnected = true

Are DriveType Host Device or Datastore ISO File

And Datastore ISO File is not a Shared LUN

Name      DriveType            Connected           StartConnected           ISOPath

gggggV1 Datastore ISO File TRUE     FALSE           [] /usr/lib/vmware/isoimages/linux.iso

jjjjjjjj01pv Datastore ISO File FALSE      TRUE           [] /usr/lib/vmware/isoimages/linux.iso

gGGGgV1 Host Device      TRUE     FALSE          

jjjjLLLj01pv  Host Device      FALSE      TRUE          

NrrrrrV      Datastore ISO File TRUE  TRUE                                          [S_LUN1] iso/Win2KSESP4.iso

VVddddV      Datastore ISO File TRUE  TRUE  [A_LUN001] iso/GImage/LiteTouchPE_x64.iso

CWI01PV      Datastore ISO File FALSE  FALSE  [] /vmimages/tools-isoimages/windows.iso

hhhh2sv      Datastore ISO File FALSE  FALSE  [] /usr/lib/vmware/isoimages/linux.iso

zzzzP14      Datastore ISO File FALSE  FALSE  []


Modified Script

$Name = "*"

$vmCol = Get-VM -Name $Name

$Output = @()

foreach ($vm in $vmCol) {

    $vm | Get-CDDrive | ForEach-Object {

        $process = "" | select Name, DriveType, Connected, StartConnected, ISOPath

        $process.Name = $vm.Name

  switch ( $_ ) {

            { $_.IsoPath }        { $process.DriveType = "Datastore ISO File" }

            { $_.HostDevice }    { $process.DriveType = "Host Device" }

            default                { $process.DriveType = "Client Device " }

        }

        $process.Connected = $_.ConnectionState.Connected

  $process.StartConnected = $_.ConnectionState.StartConnected

  $process.ISOPath = $_.ISOPath

  $Output += $process

}

}

$Output | Export-Csv $filelocation -NoTypeInformation

0 Kudos