WMI query with multiple and/or conditions?

I am using Ruby to write a format disk script. I am using WMI to
differentiate local logical disks from virtual floppies, CD-roms, and
attached SAN disks. The differentiation is in the win32_DiskDrive
class, under the “caption” section. Since this script will be run on
VMs, HP, or Dell, I need it to look for multiple conditions, and I’m not
sure how to do it. Here is a section of code that works when only
looking for VM disks:

require ‘ruby-wmi’
logical_disks = WMI::Win32_DiskDrive.find(:all, :conditions => {
:Caption => ‘VMware Virtual disk SCSI Disk Device’ } )

Can I add multiple conditions to it, such as two other potential
:Captions? Some way to do an ‘or’ in there so it will capture data from
either VMware Virtual Disks, or HP Logical Disks, or Dell Perc, etc?

On Thu, Aug 2, 2012 at 9:45 AM, Charlie B. [email protected] wrote:

I am using Ruby to write a format disk script. I am using WMI to
differentiate local logical disks from virtual floppies, CD-roms, and
attached SAN disks. The differentiation is in the win32_DiskDrive
class, under the “caption” section. Since this script will be run on
VMs, HP, or Dell, I need it to look for multiple conditions, and I’m not
sure how to do it. Here is a section of code that works when only
looking for VM disks:

You can use a string for :conditions.

WMI::Win32_DiskDrive.find(:all, :conditions => “Caption = ‘VMware
Virtual disk SCSI Disk Device’ OR Caption = ‘HP drive’ OR Caption =
‘VMWare drive’” )

A few other options that occured to me are; WIn32_DiskDrive already
eliminates non-disk drives. So, if I’m reading it right, you really
only need to eliminate SAN drives. So, assuming your SAN disks have a
model of PowerDevice by PowerPath, you could do:

WMI::Win32_DiskDrive.find(:all, :conditions => “model !=‘PowerDevice
by PowerPath’” )

or

WMI::Win32_DiskDrive.all( :conditions => “NOT model LIKE ‘%PowerPath%’”
)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs