Mart
(KiX Supporter)
2009-08-24 12:38 PM
Get fixed disks and corresponding data using WMIQuery

Been staring at this for some time now and cant find where it goes wrong. The script below fails to get the type of the drive.

According to the comment in the WMIQuery UDF it should be possible to give it a where parameter. That is what the "Caption", $drive is supposed to do but I get empty results. Anyone got a bright idea?

Maybe it is something small and stupid and I’ve been staring at it for to long so I’m just not seeing it.

 Code:
$computer = "System1"

$drives = WMIQuery("Caption","Win32_LogicalDisk", $computer)

For Each $drive in $drives
	$type = WMIQuery("Type","Win32_LogicalDisk", $computer, "Caption", $drive)
	If $type[0] = 2
		;0 = Unknown type of drive, 1 = Removable drive, 2 = Fixed drive
		;3 = Network drive, 4 = CD/DVD drive, 5 = RAM Disk
		?"Fixed disk"
	EndIf
Next


Richard H.Administrator
(KiX Supporter)
2009-08-24 01:55 PM
Re: Get fixed disks and corresponding data using WMIQuery

There are two problems:
  1. The UDF works in asynchronous mode, so you don't get an error back when you specify an invalid query.
  2. Your query is invalid - you want to retrieve "DriveType"


Mart
(KiX Supporter)
2009-08-24 01:59 PM
Re: Get fixed disks and corresponding data using WMIQuery

Yeah just noticed that after putting it away for an hour.
Will do some updates and post back.


Glenn BarnasAdministrator
(KiX Supporter)
2009-08-24 01:59 PM
Re: Get fixed disks and corresponding data using WMIQuery

This code works fine.. the "what" argument of "Type" doesn't seem valid on any sytem I've checked.
Glenn


Richard H.Administrator
(KiX Supporter)
2009-08-24 02:00 PM
Re: Get fixed disks and corresponding data using WMIQuery

BTW, if you want to see errors, change the query line in the UDF like so:
 Code:
	$objEnum = $SystemSet.ExecQuery($sQuery,"WQL",0)


Useful for small queries, but may cause issues for very long / large queries.


Arend_
(MM club member)
2009-08-24 02:09 PM
Re: Get fixed disks and corresponding data using WMIQuery

Btw, if you want a faster approach then WMI, I've written a UDF for myself a long time ago using the File System Object:
 Code:
Function GetDrives
  Dim $fso, $DriveCol, $Drive, $drv
  $fso = CreateObject("Scripting.FileSystemObject")
  $DriveCol = $fso.Drives
  For Each $Drive in $DriveCol
    $drv = $fso.GetDrive($Drive)
    ? "Drive: "+$drv
    If $drv.DriveType <> 4
      ? "Volume: "+$drv.VolumeName
      ? "Total: "+$drv.TotalSize
      ? "Free: "+$drv.FreeSpace
    EndIf
    ? "Type: "+$drv.DriveType ;1 = Removable, 2 = HDD, 3 = Network, 4 = CD
    ?
  Next
EndFunction


Although this is only for local systems.


Mart
(KiX Supporter)
2009-08-24 02:23 PM
Re: Get fixed disks and corresponding data using WMIQuery

 Originally Posted By: apronk

.....
Although this is only for local systems.


Used this approach before and it works great. Now I need the data from remote systems so in this case this is not the best option.


Arend_
(MM club member)
2009-08-24 02:32 PM
Re: Get fixed disks and corresponding data using WMIQuery

Or run this script using my RemoteRunAs UDF ;-)

Mart
(KiX Supporter)
2009-08-24 02:37 PM
Re: Get fixed disks and corresponding data using WMIQuery

Got several options now. I must be able to pull out some working code. Will post back when I'm done.

Glenn BarnasAdministrator
(KiX Supporter)
2009-08-24 03:06 PM
Re: Get fixed disks and corresponding data using WMIQuery

I gave up entirely on remote query via WMI. My latest version of SIT (System Interrogation Tool) uses TCP socket connections to make requests and return data that's gathered, processed, and formatted locally. MUCH faster! SIT used to take almost a minute to initially gather 50-60 pieces of information, mostly via WMI calls. Using a combination of local registry, WMI, and FSO, the initial query now completes in about 10 seconds.

Glenn