#29374 - 2002-09-20 07:51 PM
WMIQuery DriveType 3 list
|
Anonymous
Anonymous
Unregistered
|
Hi!
I'm noodling around with the WMIQuery UDF script and have modified it to meet my nefarious ends, but there's one last bit I haven't been able to figure out.
I would like to spit out a text file with the drive name, file system, drive size, and free space for each local drive like so:
code:
C: NTFS 79990847488 74390184960 D: NTFS 79990847488 74390184960 E: NTFS 79990847488 74390184960
I'm guessing you split the info for drive type 3 the same way it's done for dimms and nics in the WMIQuery UDF script:
code:
For Each $dimm in Split(WMIQuery("Capacity","Win32_PhysicalMemory"),"|") $DimmMem = Val($dimm) / 1048576 WriteLine(6, @wksta + chr(9) + $DimmMem + Chr(13) + Chr(10)) Next
I can't figure that part out, though. The dimm and nic examples only deal with one bit of info ($dimm and $nic), but I need 4 bits per local disk ($drivename, $filesystem, $drivesize, and $freespace).
Plus, the PC I'm testing this all on only has one partition so even if I could figure it out I'd never be sure if it was working.
I'm pulling the info for local disks like so:
code:
$DriveName = WMIQuery("Name","Win32_LogicalDisk",,"DriveType","3") $FileSystem = WMIQuery("FileSystem","Win32_LogicalDisk",,"DriveType","3") $FreeSpace = WMIQuery("FreeSpace","Win32_LogicalDisk",,"DriveType","3") $DriveSize = WMIQuery("Size","Win32_LogicalDisk",,"DriveType","3")
...but that only gives me info for drive c:
I hope I'm explaining this clear enough...
Many thanks in advance for any help. Truly appreciated.
|
Top
|
|
|
|
#29375 - 2002-09-20 08:45 PM
Re: WMIQuery DriveType 3 list
|
Waltz
Seasoned Scripter
Registered: 2002-08-01
Posts: 485
Loc: Waterloo, Ontario, Canada
|
This is work in progress, but it may give you some clues, as I'm working towards the same objective. Function dependencies are wmiquery(), words(), word() which you can find in the UDF forum on this BB. code:
; ;local disk info $numparts=WMIQuery("Partitions","Win32_DiskDrive","$machine") $disksize=WMIQuery("Size","Win32_DiskDrive","$machine") $index1=0 FOR EACH $item IN SPLIT(WMIQuery("DriveType","Win32_LogicalDisk","$machine"),"|") $index1=$index1+1 IF TRIM($item) == "3" $disktype=$disktype+" "+$item $index2=0 FOR EACH $item IN SPLIT(WMIQuery("DeviceID","Win32_LogicalDisk","$machine"),"|") $index2=$index2+1 IF $index1==$index2 $diskid=$diskid+" "+$item $index3=0 FOR EACH $item IN SPLIT(WMIQuery("FreeSpace","Win32_LogicalDisk","$machine"),"|") $index3=$index3+1 IF $index1==$index3 $diskfree=$diskfree+" "+$item $index4=0 FOR EACH $item in SPLIT(WMIQuery("FileSystem","Win32_LogicalDisk","$machine"),"|") $index4=$index4+1 IF $index1=$index4 $filesys=$filesys+" "+$item ENDIF NEXT ENDIF NEXT ENDIF NEXT ENDIF NEXT
;?? "TEST OUTPUT" ? "total local disk size = "$disksize" Bytes" ? "number of disk partitions = "$numparts ;rearrange the strings $m="" for $j = $numparts to 1 step -1 $m = $m +" "+word($disktype,$j) next $disktype=$m ? "local disk type(s) = "$disktype $m="" for $j = $numparts to 1 step -1 $m = $m +" "+word($diskid,$j) next $diskid=$m ? "local disk name(s) = "$diskid $m="" for $j = $numparts to 1 step -1 $m = $m +" "+word($diskfree,$j) next $diskfree=$m ? "local disk free space(s) = "$diskfree" Bytes" $m="" for $j = $numparts to 1 step -1 $m = $m +" "+word($filesys,$j) next $filesys=$m ? "local disk file system(s) = "$filesys ;
Hope this helps... [ 20. September 2002, 21:55: Message edited by: Waltz ]
_________________________
We all live in a Yellow Subroutine...
|
Top
|
|
|
|
#29376 - 2002-09-20 08:55 PM
Re: WMIQuery DriveType 3 list
|
kholm
Korg Regular
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
This is a 'rebuild' of the script i use to keep track of the disks in my servers
The function: DiskInfo() returns an array of diskinfo on the form: Drive,Filesystem,Size,FreeSpace
code:
Function DiskInfo($PC) Dim $Disks[0],$NumDisks,$Found,$Row $DiskInfo = 0 $NumDisks = 0 $Found = 0 $Row = '' $objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + $PC) If @Error Return EndIf $colDisks = $objWMI.ExecQuery("Select * From win32_logicalDisk") For Each $objDisk In $colDisks If $objdisk.mediatype = 12 $Row = $objdisk.name + ',' $Row = $Row + $objdisk.FileSystem + ',' $Row = $Row + $objDisk.size + ',' $Row = $Row + $objDisk.FreeSpace ReDim Preserve $Disks[$NumDisks] $Disks[$NumDisks] = $Row $NumDisks = $NumDisks + 1 $Row = '' $Found = 1 EndIf Next $objWMI = 0 If $Found $DiskInfo = $Disks EndIf EndFunction
; * Test code Break On
$PC = 'Server1' For Each $Disk In DiskInfo($PC) $Disk ? Next
Get $x
Return ; * End Test code
-Erik [ 21. September 2002, 18:50: Message edited by: kholm ]
|
Top
|
|
|
|
#29377 - 2002-09-20 09:26 PM
Re: WMIQuery DriveType 3 list
|
Anonymous
Anonymous
Unregistered
|
Alas, Waltz, I couldn't get your script to run.
Kholm, your script works just fine and dandy, but it sort of hangs for a good long while (15+ seconds) before returning the prompt.
In my attempt to get the output to a text file, I tried:
code:
$PC = @wksta if open(9, "s:\computing\scripts\" + @wksta + "_dr.txt",5) = 0 For Each $Disk In DiskInfo($PC) $Disk ? writeline(9, @wksta + chr(9) + $objdisk.name + chr(9) + $objdisk.filesystem + chr(9) + $objdisk.size + chr(9) + $objdisk.freespace + chr(13) + chr(10)) close (9) Next else ? "File open error = " @error endif
Get $x
Return
Kinda odd. The file never opens, but the script continues to run as if it did. My screen output is:
code:
S:\COMPUT~1\scripts>kix32 dr C: NTFS 79990847488 74390422016 00
I modified the output to use tabs instead of commas. So it spits out the drive info then spits out the two 0's, but then hangs.
Any ideas? (other than I need to learn how to do this stuff on my own
Thanks.
|
Top
|
|
|
|
#29380 - 2002-09-20 09:50 PM
Re: WMIQuery DriveType 3 list
|
kholm
Korg Regular
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Shane,
You don't get the object returned from DiskInfo(), but an array of comma separated strings.
After your rebuild it will return an array of tabulator separated strings, and you should write it directly to the file.
Use it like this:code:
$PC = @wksta if open(9, "s:\computing\scripts\" + @wksta + "_dr.txt",5) = 0 For Each $Disk In DiskInfo($PC) $Disk ? $RC = writeline(9, $Disk + @CRLF) $RC = close (9) Next else ? "File open error = " @error endif
Get $x
Return
-Erik
|
Top
|
|
|
|
#29381 - 2002-09-20 10:18 PM
Re: WMIQuery DriveType 3 list
|
Anonymous
Anonymous
Unregistered
|
I must be doing something very wrong cause it just hangs and never writes a file (though it does output to screen). I have to hit ctrl-z to get the prompt back.
Here is the whole script as I have it now:
code:
; * Test code $PC = @wksta if open(9, "s:\computing\scripts\" + @wksta + "_dr.txt",5) = 0 For Each $Disk In DiskInfo($PC) $Disk ? $RC = writeline(9, $Disk + @CRLF) $RC = close (9) Next else ? "File open error = " @error endif
Get $x
Return
; * End Test code
Function DiskInfo($PC) Dim $Disks[0],$NumDisks,$Found,$Row $DiskInfo = 0 $NumDisks = 0 $Found = 0 $Row = '' $objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + $PC) If @Error Return EndIf $colDisks = $objWMI.ExecQuery("Select * From win32_logicalDisk") For Each $objDisk In $colDisks If $objdisk.mediatype = 12 Dim $Row[4] $Row = $objdisk.name + chr(9);',' $Row = $Row + $objdisk.FileSystem + chr(9) ;',' $Row = $Row + $objDisk.size + chr(9) ;',' $Row = $Row + $objDisk.FreeSpace ReDim Preserve $Disks[$NumDisks] $Disks[$NumDisks] = $Row $NumDisks = $NumDisks + 1 $Row = '' $Found = 1 EndIf Next $objWMI = 0 If $Found $DiskInfo = $Disks EndIf EndFunction
Any reason why it would be hanging? Geez, I feel like an idiot.
In my 8th grade science class I was the only kid whose fake volcanoe didn't work. Go figure... [ 20. September 2002, 22:21: Message edited by: Shane ]
|
Top
|
|
|
|
#29384 - 2002-09-23 02:43 PM
Re: WMIQuery DriveType 3 list
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
look at this for a different approach.
$HD =WMIQuery("Size","Win32_DiskDrive") $hdGB =left($hd,len($hd)-9)
WMIQuery will retrieve all your info, you just need to specifiy where you are getting it from....
|
Top
|
|
|
|
#29386 - 2002-09-23 05:58 PM
Re: WMIQuery DriveType 3 list
|
Anonymous
Anonymous
Unregistered
|
Thanks a lot guys. I have it sorta/kinda working with Waltz' suggestion:
code:
if exist ("s:\computing\scripts\wksta\" + @wksta + "_dr.txt") goto "over" else $PC = @wksta $outfile = "s:\computing\scripts\wksta\" + @wksta + "_dr.txt" if redirectoutput ($outfile,1) = 0 For Each $Disk In DiskInfo($PC) $Disk ? Next ; redirectoutput ("") endif ; redirectoutput ("") return ; redirectoutput ("") endif
; redirectoutput ("") ? "stuff for the screen" :over
Problem is, I can't get it to redirect the output back to the screen.
I've tried code:
redirectoutput ("")
like it says in the Kixtart help, but it won't spit stuff out back to the screen. I've put the command after the NEXT, after the nested ENDIF, after the RETURN, and after the bottom ENDIF. "Stuff for the screen" never makes it to the screen, however.
What am I doing wrong?
|
Top
|
|
|
|
#29388 - 2002-09-23 06:24 PM
Re: WMIQuery DriveType 3 list
|
Anonymous
Anonymous
Unregistered
|
Jens, I'm only showing where I've tried putting them. When I was trying it out one of them was uncommented.
|
Top
|
|
|
|
#29389 - 2002-09-23 06:36 PM
Re: WMIQuery DriveType 3 list
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
does this do what you need???
code:
$name= split(wmiquery("name","win32_logicalDisk"),"|") $fs= split(wmiquery("filesystem","win32_logicalDisk"),"|") $size= split(wmiquery("size","win32_logicalDisk"),"|") $fsp= split(wmiquery("freespace","win32_logicalDisk"),"|")
for $loop=0 to ubound($name) ? $name[$loop]" "$fs[$loop]" "$size[$loop]" "$fsp[$loop] next
|
Top
|
|
|
|
#29391 - 2002-09-23 06:42 PM
Re: WMIQuery DriveType 3 list
|
Anonymous
Anonymous
Unregistered
|
Radimus:
Well, I'm not sure. First off, I only need the local drives. I only have one local partition so I can't see if your script spits out info for more than one local parition.
If I could get that for all local partitions on a system then, yes, that's what I need.
Thanks!
|
Top
|
|
|
|
#29392 - 2002-09-23 06:47 PM
Re: WMIQuery DriveType 3 list
|
Anonymous
Anonymous
Unregistered
|
Waltz:
Your latest offering fares no better against this vile problem. I get the disk info output to the screen, then text file is written, but the "Stuff for the screen" is never displayed on the screen.
My prompt:
code:
S:\computing\scripts>kix32 inventory C: NTFS 79990847488 73850057728
S:\computing\scripts>_
Weird.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 259 anonymous users online.
|
|
|