none
Need help from VB Scripting Gods RRS feed

  • Question

  • I am very new to VB Scripting; I now have a problem that I cannot resolve by myself with the help of some of the scripting experts.

     

    I have a text file that consists of user share names (CidMpfu.txt).

    The server name apgrfsga-homes

    The ObjInputFile is reading in lines from CidMpfu.txt.

                    james.p.ryan1

    I need to add a $ to the name above.

    The WMI output is in a different format (wmiOutput.txt)

    User: Win32_Account.Domain="NAE",Name="carl.wheeler"

    DiskSpaceUsed: 34816

    I need to match up the ObjInputFile and wmi data.

    I am getting NULL error

    The wmi is not catching all data folder from server directory tree

                    This I am at a lost on (HELP)

    Please review server and CIM Studio figures.

    All other help is welcome.

     

    Here is a copy of the script i am working with.

     

    strComputer = "apgrfsgag-homes"

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objInputFile = fso.OpenTextFile("D:\QuotaManagement\CidMpfu.txt",1,True)

    Do While ObjInputFile.AtEndOfLine <> True
     strUser = ObjInputFile.ReadLine
     
     Set objWMIService = GetObject("winmgmts:" _
         & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        
     Set colUser = objWMIService.ExecQuery _
        ("Select User, DiskSpaceUsed from Win32_DiskQuota WHERE User=strUser")
       
    For Each objUser in colUser
        WScript.Echo "User: " & colUser.User
        WScript.Echo "DiskSpaceUsed: " & colUser.DiskSpaceUsed
    Next

    Loop

     

    A copy of the text file.

    james.p.ryan1    
    kyle.sbarbaro    

     

    A copy of the wmi output.

     

    User: Win32_Account.Domain="NAE",Name="carl.wheeler"
    DiskSpaceUsed: 34816

     

     

     

     

     

     

    Thanks

    Robert

    Monday, June 7, 2010 2:01 PM

Answers

  • In your first script, I would try:

     Set colUser = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_DiskQuota " _
     & "WHERE User='Win32_Account.Domain=""NAE"",Name=""" & strUser & """'")
    

     

    The error was due to the string value continuing from one line to the next. You must make it into two strings and concatenate with the & character, as above. I don't know if the value is correct, but it should match the output you posted earlier.

    Richard Mueller


    MVP ADSI
    • Marked as answer by RobertLamar Wednesday, August 25, 2010 4:53 PM
    Wednesday, June 16, 2010 5:20 PM
    Moderator

All replies

  • You need to concatenate the user name (the value of strUser) to the rest of the query string, using the "&" concatenation operator. Also, the string value in the query need to be enclosed in single quotes. Instead of:

    Set colUser = objWMIService.ExecQuery _
      ("Select User, DiskSpaceUsed from Win32_DiskQuota WHERE User=strUser")
    

     

    user:

    Set colUser = objWMIService.ExecQuery _
      ("Select User, DiskSpaceUsed from Win32_DiskQuota WHERE User='" & strUser & "'")
    

     

    Richard Mueller


    MVP ADSI
    Monday, June 7, 2010 2:15 PM
    Moderator
  • Give this a whirl:

    Set colUser = objWMIService.ExecQuery("Select * from Win32_DiskQuota")
      
    For Each objUser in colUser
        if instr(objuser.user, strUser) >0 then   
            WScript.Echo "User: " & objUser.User
                WScript.Echo "DiskSpaceUsed: " & objUser.DiskSpaceUsed
        end if
    Next

    Monday, June 7, 2010 2:20 PM
  • post your code. We do not know if you used my solution or Richard's.
    Monday, June 7, 2010 5:00 PM
  • First, line 19 in my copy of your code is a blank line. My guess is the line is:

    For Each objUser In colUser

    Next, I'm sure you are aware that the Win32_DiskQuota class is only available on XP and above. Also, as pointed out, I believe you should use "SELECT *", rather than specifying the properties. For example:

    Set colUser = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_DiskQuota WHERE User='" & strUser & "'")
    

    Finally, as also suggested, you might try NastyMatt's suggestion, at least to troubleshoot:

    Set colUser = objWMIService.ExecQuery _
     ("Select User, DiskSpaceUsed from Win32_DiskQuota")
    
    For Each objUser In colUser
      Wscript.Echo "User: " & objUser.User
      Wscript.Echo "DiskSpaceUsed: " & objUser.DiskSpaceUsed
    Next

     

    Oh, and I just noticed that you used colUser.User rather than objUser.User in your loop. Perhaps that accounts for your error. In any case, my thought was that the error could mean the collection is empty, in which case the objUser.User property is not what you expect. The query that retrieves info on all users is less efficient, but at least you should be output to help you troubleshoot. Then you can try the more efficient query with the WHERE clause.

    Richard Mueller


    MVP ADSI
    Monday, June 7, 2010 5:10 PM
    Moderator
  • Clearly, the value of objUser.User is not in a format we expect. This accounts for the collection colUsers being empty (Null) when you use a WHERE clause. I can find no documentation on the User property, but your experience actually makes sense, as the name should include the NetBIOS name of the domain. I would expect a typical value of the User property to be:

    NAE\catherine.j.young

    It would be worth trying the following WHERE clause:

    Set colUser = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_DiskQuota WHERE User='NAE\" & strUser & "'")
    

     

    Less likely, based on the output you get without a WHERE clause, the following might work:

     

    Set colUser = objWMIService.ExecQuery _
      ("SELECT * FROM Win32_DiskQuota _
      WHERE User='Win32_Account.Domain=""NAE"",Name=""" & strUser & """'")
    

    The best solution might be to omit the WHERE clause and test for the user name in the "For Each/Next", similar to below:

    Set colUser = objWMIService.ExecQuery _
      ("SELECT * FROM Win32_DiskQuota")
    
    For Each objUser In colUser
      If (InStr(objUser.User, strUser) > 0) Then
        Wscript.Echo "User: " & objUser.User
        Wscript.Echo "DiskSpaceUsed: " & objUser.DiskSpaceUsed
      End If
    Next

     

    If you don't want to output the user name in the format used by the objUser.User property, then replace it with strUser in the Wscript.Echo statement. That is:

    Wscript.Echo "User: " & strUser
    

    Richard Mueller


    MVP ADSI
    Tuesday, June 8, 2010 2:11 PM
    Moderator
  • Have you tried my original suggestion?

     

    Set colUser = objWMIService.ExecQuery("Select * from Win32_DiskQuota")
      
    For Each objUser in colUser
        if instr(objuser.user, strUser) >0 then   
            WScript.Echo "User: " & objUser.User
                WScript.Echo "DiskSpaceUsed: " & objUser.DiskSpaceUsed
        end if
    Next

    Tuesday, June 8, 2010 2:12 PM
  • In your first script, I would try:

     Set colUser = objWMIService.ExecQuery _
     ("SELECT * FROM Win32_DiskQuota " _
     & "WHERE User='Win32_Account.Domain=""NAE"",Name=""" & strUser & """'")
    

     

    The error was due to the string value continuing from one line to the next. You must make it into two strings and concatenate with the & character, as above. I don't know if the value is correct, but it should match the output you posted earlier.

    Richard Mueller


    MVP ADSI
    • Marked as answer by RobertLamar Wednesday, August 25, 2010 4:53 PM
    Wednesday, June 16, 2010 5:20 PM
    Moderator