Results 1 to 10 of 10

Thread: [RESOLVED] freespace report - pulling my hair :(

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    9

    Resolved [RESOLVED] freespace report - pulling my hair :(


    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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    9

    Re: freespace report - pulling my hair :(

    thanks westconn. i deleted the loop statements.

    don't what causes those repetitions. how do i avoid them?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    9

    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??

    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    9

    Re: freespace report - pulling my hair :(

    pete

    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
    Last edited by rrwillu; Oct 7th, 2007 at 07:47 PM.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    9

    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

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: freespace report - pulling my hair :(

    oops somewhere i forgot this is a script, not vb

    this works

    vb Code:
    1. x = "this is a string"
    2.  
    3. if not x="" then mysub ' x is in an if
    4. msgbox "continued"
    5.  
    6. sub mysub()
    7.     msgbox x
    8. end sub

    try like this to exit for, but 2 minutes is a bloody long time
    vb Code:
    1. tval = Timer()
    2. For Each objItem In colItems
    3. wfile.writeline (servername & "," & objItem.Name & "," & "Freespace: " & FormatNumber(objItem.Freespace / 1024 / 1024 / 1024))
    4. If Timer - tval > 120 Then Exit For '2mins *60 secs
    5. Next
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    9

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width