#125211 - 2004-08-18 02:51 PM
Help please with WMI query
|
bowhuntr
Fresh Scripter
Registered: 2002-02-18
Posts: 33
|
I am trying to get the size value of each physical hard drive in a machine. I am able to get the value of the first drive but can't seem to figure out how to code it to get the value of each drive if there is more than one present. Here is the code I'm using please help if you can. Thanks!
Code:
$Dsks = GetObject("winmgmts://$computername").ExecQuery("select * from Win32_DiskDrive") if @error <> 0 ? @error + " / " @serror ? ? shell "%comspec% /c pause" else for each $Item in $Dsks $TotalDsks = $Item.Size If $TotalDsks = "" $TotalDsks = "NULL" else endif next endif
|
Top
|
|
|
|
#125213 - 2004-08-18 03:25 PM
Re: Help please with WMI query
|
Anonymous
Anonymous
Unregistered
|
OK, that does echo all the drives, but I need to assign each one a variable so I can redirect the output to a file along with all the other info I'm capturing. How can I go about doing it that way?
|
Top
|
|
|
|
#125214 - 2004-08-18 05:01 PM
Re: Help please with WMI query
|
bowhuntr
Fresh Scripter
Registered: 2002-02-18
Posts: 33
|
I assume the best way to do this is create an array on the fly from the data I get back from $Item.Size. Then I could echo the array contents into my file. Can someone point me in the right direction? I am unsure how to create the array on the fly or to echo the array contents when I don't now how many drives exist. Thanks!
|
Top
|
|
|
|
#125216 - 2004-08-18 06:07 PM
Re: Help please with WMI query
|
bowhuntr
Fresh Scripter
Registered: 2002-02-18
Posts: 33
|
Jooel,
I have tried to run your code as you wrote it (with the exception of replacing $computername with and actual computer name) and I get an error on the second line. Code:
$Dsks = GetObject("winmgmts://$computername").ExecQuery("select * from Win32_DiskDrive")
The error is: Error: unexpected command!
What am I doing wrong? Kix 4.21 if it matters.
|
Top
|
|
|
|
#125218 - 2004-08-18 09:02 PM
Re: Help please with WMI query
|
bowhuntr
Fresh Scripter
Registered: 2002-02-18
Posts: 33
|
This is the code I am trying to run in a script all by itself. There is no other code on the page and I replace $computername with a real machine name on my network I have full access to.
Code:
$drives[0] $Dsks = GetObject("winmgmts://rlg012kd").ExecQuery("select * from Win32_DiskDrive") if @error "Error occured: " @error " " @serror ? "Press the anyKey to quit" get $key quit endif for each $Item in $Dsks ;dim again preserving the data that is in the array. ;redim with upper bound (the element amount) of array added by one. redim preserve $drives[ubound($drives)+1] $drives[ubound($drives)]= $Item.Size ;place the data to the last element next
I get the error unexpected command! and its complaining abot the line thats starts with $Dsks = . If I comment out the first line the error goes away but then I wouldn't get the array either. Any ideas?
|
Top
|
|
|
|
#125224 - 2004-08-18 11:16 PM
Re: Help please with WMI query
|
bowhuntr
Fresh Scripter
Registered: 2002-02-18
Posts: 33
|
OK, I don't get an error now since I put the dim statement before $drives[0] . If this is actually creating an array with the size of all the disk drives listed in it how do I access the results of the array? the ultimate goal is to be able to redirect the output to a file but for now I will settle for having it on screen. So far I have tried to do ? "$drives[1] , etc and get nothing. Also how would I handle echoing all the results out to the screen or a file when I don't know how many elements the array contains?
Thanks for everyones help. I really hate being such a pest with what are to you probably silly newbie questions.
|
Top
|
|
|
|
#125226 - 2004-08-19 01:19 PM
Re: Help please with WMI query
|
bowhuntr
Fresh Scripter
Registered: 2002-02-18
Posts: 33
|
and how do I go about seeing the results of that?
|
Top
|
|
|
|
#125228 - 2004-08-19 01:58 PM
Re: Help please with WMI query
|
bowhuntr
Fresh Scripter
Registered: 2002-02-18
Posts: 33
|
I have read the manual and paid close attention to the section on arrays. If I found the answer there (or one I understood) I wouldn't be asking here. I offer my sincerest thanks for your help thus far, but it appears I have worn out my welcome.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|