[RESOLVED] freespace report - pulling my hair :(
:mad:
All:
Below is my freespace script for all the servers. My server list is dynamic based on ADO objects (thru Active directory)
For some strange reason for exch03, i'm getting repetitions before it goes to exch04.
I pulled my hair for too many days and too long...have tried EVERYTHING i know of. This thread is my last resort.
Can someone help me figure why i'm getting repetitions for Exch03!!!????? Thanks
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer, "root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 3")
For Each objItem In colItems
wfile.writeline (servername & "," & objItem.Name & "," & "Freespace: " & FormatNumber(objItem.Freespace/1024/1024/1024))
Next
Output:
exch01, C:, Freespace: 45
exch01, D:, Freespace: 17
exch01, E:, Freespace: 21
exch01, M:, Freespace: 8
exch02, C:, Freespace: 39
exch02, E:, Freespace: 76
exch03, C:, Freespace: 3
exch03, E:, Freespace: 19
exch03, C:, Freespace: 3
exch03, E:, Freespace: 19
exch03, C:, Freespace: 3
exch03, E:, Freespace: 19
exch03, C:, Freespace: 3
exch03, E:, Freespace: 19
------------------------------------------------------------
I thought i was smart when I looped only for colItems.Count hoping
the exch03 will not show up four times, but below is the output
------------------------------------------------------------
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer, "root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 3")
Items = colItems.Count
For Each objItem In colItems
Do Until Items = 0
Items = Items - 1
wfile.writeline (servername & "," & objItem.Name & "," & "Freespace: " & FormatNumber(objItem.Freespace/1024/1024/1024))
Loop
Next
OUTPUT:
exch01, C:, Freespace: 45
exch01, C:, Freespace: 45
exch01, C:, Freespace: 45
exch01, C:, Freespace: 45
exch02, C:, Freespace: 39
exch02, C:, Freespace: 39
exch03, C:, Freespace: 3
exch03, C:, Freespace: 3
exch03, C:, Freespace: 3
exch03, C:, Freespace: 3
exch03, C:, Freespace: 3
exch03, C:, Freespace: 3
exch03, C:, Freespace: 3
exch03, C:, Freespace: 3
Re: freespace report - pulling my hair :(
just limiting the number of times you loop will not change the items that are looped, only cut short the list
also Items seems to be reserved word
Re: freespace report - pulling my hair :(
thanks westconn. i deleted the loop statements.
don't what causes those repetitions. how do i avoid them?
Re: freespace report - pulling my hair :(
not sure as i could only test on my local machine, it only returned a single server drive, being my c: drive
try putting a break point in your code and looking in the locals window at what is returned
possibly active directory is returning multiple instances of servers
Re: freespace report - pulling my hair :(
thanks for trying on your local machine pete.
yes i'm pulling from active directory, but not sure why AD will pull same server names??:confused:
This is the code I'm using..
mbQuery = "<LDAP://" & StartPoint & ">;(objectCategory=msExchPrivateMDB);name,distinguishedName,msExchOwningServer,msExchEDBFile;subtree "
Com.ActiveConnection = Conn
Com.CommandText = mbQuery
Set Rs = Com.Execute
While Not Rs.EOF
servername = Mid(Rs.Fields("msExchOwningServer"), 4, InStr(Rs.Fields("msExchOwningServer"), ",") - 4)
strComputer = servername
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer, "root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 3")
For Each objItem In colItems
wfile.writeline (servername & "," & objItem.Name & "," & "Freespace: " & FormatNumber(objItem.Freespace/1024/1024/1024))
Next
rs.move next
the "rs.move next" command should pass me onto another server name, instead of passing on same or duplicate name.
Now assuming AD is pulling duplicate names, can we insert another check in between? Like, Do while servername = ?????
Or can we, NOT use "For Each objItem In colItems" loop and instead use colItems.Name or something? I know the answer is NO and i tried too, but wanted to ask anyway.
Re: freespace report - pulling my hair :(
pete :wave:
yep, i implemented my first suggestion and it worked :) I inserted another check in between rs.movenext. here it is...
--------------------------
servername = ""
While Not rs.EOF
strComputer = Mid(rs.Fields("msExchOwningServer"), 4, InStr(rs.Fields("msExchOwningServer"), ",") - 4)
If strComputer = servername Then
rs.movenext
Else
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer, "root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_LogicalDisk Where DriveType = 3")
For Each objItem In colItems
wfile.writeline (servername & "," & objItem.Name & "," & "Freespace: " & FormatNumber(objItem.Freespace/1024/1024/1024))
Next
End If
rs.move next
Thanks again pete for your valuable input.
-----------------------
I have another issue, which is WMI hanging and declaring global variable
I have
Public Sub Main()
ag = Command$
If ag = 1
call quit
else
call exec
End Sub
Private exec()
msgbox (ag)
End Sub
My prb is, ag value is not being transfered to another sub. I was reading that if we use "IF" function, the values can't be passed on to another sub (block variable, i think those are called).
I was trying PUblic ag as String, but VB6 is throwing me errors
Also, as mentioned WMI just hangs with this particular computer for hours!!!
I used "EXIT FOR" function but didn't work, because the WMI connection is not releasing.
tval = timer()
if tval = 2
exit for
else
For Each objItem In colItems
wfile.writeline (servername & "," & objItem.Name & "," & "Freespace: " & FormatNumber(objItem.Freespace/1024/1024/1024))
Next
i typed timer() function vaguely, but the idea is for 2 minutes i wanted to exit the 'for each ...' loop
Re: freespace report - pulling my hair :(
you can certainly pass arguments when you call a sub
exec ag
sub exec(str as string)
for your global variable, did you declare it in the general section of the module?
also command remains in scope throughout, so you can just use it in the exec sub
Re: freespace report - pulling my hair :(
No Pete...there is no module. The entire script is pasted above.
To declare global variable, i put module statement, but it didn't work and VB6 didn't like it either.
module freespace
.....
end module
Passing the value to another Sub, i didn't get yoru suggestion, can you paste below how it looks like including module line? thanks
Re: freespace report - pulling my hair :(
oops somewhere i forgot this is a script, not vb
this works
vb Code:
x = "this is a string"
if not x="" then mysub ' x is in an if
msgbox "continued"
sub mysub()
msgbox x
end sub
try like this to exit for, but 2 minutes is a bloody long time
vb Code:
tval = Timer()
For Each objItem In colItems
wfile.writeline (servername & "," & objItem.Name & "," & "Freespace: " & FormatNumber(objItem.Freespace / 1024 / 1024 / 1024))
If Timer - tval > 120 Then Exit For '2mins *60 secs
Next
Re: freespace report - pulling my hair :(
thanks pete.
i corrected wmi issues instead of trying to make script do workarounds. NO timer()s or conditions :)
thanks for ur help