none
Grabbing Folder size and email info RRS feed

  • Question

  • Hi all,

     I've been working on a script that will get the size of all the users profiles folders on our file server. I then set it up to email the I.T. Dept if the size of the file is over 200MB.

    So far, when I run the script, it doesn't throw off any errors, but it doesn't send the email either.

    Information:

    The file server is added as a relay in Exchange.

    We are not using port 25, we're using an alternate port instead.

    I've tried it with both authenticate and without.

    I can telnet to the Exchange server using Putty and open a connection to the port to issue an HELO command.

    I am just learning how to script.

    The script is pasted below with the obvious omitted.

    Since the script doesn't throw an error, I can't track down the problem.

    Script us below.

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder("D:\Profiles")
    Set colSubfolders = objFolder.Subfolders
    For Each objSubfolder in colSubfolders
    foldersize = objsubfolder.Size/1024/1024                           
    Next  
    If foldersize > 200 Then
    Set objMessage = CreateObject("CDO.Message")
      objMessage.From = one.use@company.com"
      objMessage.To = "my.email@company.com"
      objMessage.Subject = " A profile Folder has exceeded 200MB"
      objMessage.TextBody = "The folder " & objSubfolder & " has exceeded 200MB.  Please panic in an orderly fashion." 
     
      objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "myemailserver"
      objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 2525

      objMessage.Configuration.Fields.Update 
     
      objMessage.Send
    End If

    SO, as I said, it's not throwing an error, but I'm not getting a test email eihter

    What am I missing?



    Tuesday, May 27, 2014 7:07 PM

Answers

  • So what is in foldersize?  What is in foldersize after you exit the loop?

    For Each objSubfolder in colSubfolders
          foldersize = objsubfolder.Size/1024/1024                           
    Next

    Wscript.Echo foldersize


    ¯\_(ツ)_/¯

    Wednesday, May 28, 2014 2:32 PM

All replies

  • So you have no big profiles.

    Try testing a few lines at a time and add trace statements.


    ¯\_(ツ)_/¯

    Tuesday, May 27, 2014 9:36 PM
  • Start by looking at these lines:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder("D:\Profiles")
    Set colSubfolders = objFolder.Subfolders
    For Each objSubfolder in colSubfolders
          foldersize = objsubfolder.Size/1024/1024                           
    Next    


    ¯\_(ツ)_/¯

    Tuesday, May 27, 2014 9:37 PM
  • I did check the profiles folders and we do have a few over 200MB.

    Thanks for giving me the starting point. As I stated above, I'm new to scripting so I'm kinda learning on the fly. 

    Tuesday, May 27, 2014 10:09 PM
  • Scripting is about thinking about what makes sense.  That loop does not make sense.  Ask yourself...what does it do?

    ¯\_(ツ)_/¯

    Tuesday, May 27, 2014 10:15 PM
  • OK,

     So I've tried this single part of the script, but added in the Echo statement:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder("D:\Profiles")
    Set colSubfolders = objFolder.Subfolders
    For Each objSubfolder in colSubfolders
    foldersize = objsubfolder.Size/1024/1024                           
    Wscript.Echo objSubfolder.Name, int(objSubfolder.Size/1024/1024) & "MB"
    Next

    It is echoing back the folder size of all the profile folders in MB...which is great, it's what I wanted it to do, however, if I add the portion back in to email, I get an error of "Object required: 'objSubfolder' 800A01A8.

    I've tried to look this particular error up and it doesn't seem to be clicking in my head as to where the problem lies. 

    Wednesday, May 28, 2014 2:26 PM
  • So what is in foldersize?  What is in foldersize after you exit the loop?

    For Each objSubfolder in colSubfolders
          foldersize = objsubfolder.Size/1024/1024                           
    Next

    Wscript.Echo foldersize


    ¯\_(ツ)_/¯

    Wednesday, May 28, 2014 2:32 PM
  • In foldersize I have objsubfolder.Size/1024/1024 - which means, it will return the size of the subfolders that I want to know.

    In foldersize after I exit the loop, I have (I'm guessing here), nothing stated? So maybe remove the Next? Like I said..guessing.

    BTW JRV, thanks for the challenge. I prefer to learn what I'm doing instead of just having the answer handed to me.

     

    Wednesday, May 28, 2014 2:54 PM
  • In foldersize I have objsubfolder.Size/1024/1024 - which means, it will return the size of the subfolders that I want to know.

    In foldersize after I exit the loop, I have (I'm guessing here), nothing stated? So maybe remove the Next? Like I said..guessing.

    BTW JRV, thanks for the challenge. I prefer to learn what I'm doing instead of just having the answer handed to me.

     

    Don't guess - learn.

    See this: http://i-rants-n-raves.blogspot.com/2014/05/some-thoughts-on-newbie-computer-kids.html


    ¯\_(ツ)_/¯

    Wednesday, May 28, 2014 2:57 PM
  • It Works!

    So, I moved it around to look like this (after your kick in the right direction):

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder("D:\Profiles")
    Set colSubfolders = objFolder.Subfolders
    For Each objSubfolder in colSubfolders
        foldersize = objsubfolder.Size/1024/1024                           
    If foldersize > 200 Then
    Set objMessage = CreateObject("CDO.Message")
      objMessage.From = "myemail.com"
      objMessage.To = "myemail.com"
      objMessage.Subject = " A profile Folder has exceeded 200MB"
      objMessage.TextBody = "The folder " & objSubfolder & " has exceeded 200MB.  Please panic in an orderly fashion." 
     
      objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "myexchangeserver"
      objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = myport
      objMessage.Configuration.Fields.Update 
     
      objMessage.Send
    End If 
    Next

    When I ran the script, it returned back, via email, the users who's profiles were over 200MB. 

    I also checked the link out. Hope you weren't pointing the virtual finger at me :P. I handle networking and server stuff on a daily basis, but this was my first foray into scripting. I do have a beginners guide at home that I've been reading as well, but this was a "we need it done now" kinda thing that I'm sure everyone in IT has dealt with.

    Anyway, thanks for the assist JRV. 

    Wednesday, May 28, 2014 3:07 PM
  • Just a suggestion for the future - skip VBScript and focus on PowerShell for your next scripting project. It'll make your life much easier.

    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    Wednesday, May 28, 2014 3:11 PM
  • That is going to send one email for each folder.  Is that what you wanted?

    More important.  Do you understand why what you posted originally doesn't work?  I do not think so?


    ¯\_(ツ)_/¯

    Wednesday, May 28, 2014 3:14 PM
  • Yes, we want one email sent, per folder.

    I'm pretty sure I understand why the OP wasn't working. I had foldersize being read, but, the script had no idea of what to do with it as I had the "Next" statement before telling the script what to do with the folders who's size was more than 200MB.

    Wednesday, May 28, 2014 3:18 PM
  • I also checked the link out. Hope you weren't pointing the virtual finger at me :P. I handle networking and server stuff on a daily basis, but this was my first foray into scripting. I do have a beginners guide at home that I've been reading as well, but this was a "we need it done now" kinda thing that I'm sure everyone in IT has dealt with.

    Your question and your answers show you do not understand how a computer works. You can learn by rote how to do things in a network. It does not mean you understand what you are doing in any fundamental technical sense.

    Try to learn logic and how a computer takes electrons and turns them into a complex thing like a GUI or a database.  If you cannot master this kind of thinking your reach in technology will be severely limited.  When you master the basics everything else becomes easier.

    Just a suggestion.


    ¯\_(ツ)_/¯

    Wednesday, May 28, 2014 3:18 PM
  • Yes, we want one email sent, per folder.

    I'm pretty sure I understand why the OP wasn't working. I had foldersize being read, but, the script had no idea of what to do with it as I had the "Next" statement before telling the script what to do with the folders who's size was more than 200MB.

    That is partly the answer. Immediately it satisfies the need but ask yourself...why didn't you see that to begin with.  Now look at a more direct method of "saying " the same thing in code.

    Set objMessage = CreateObject("CDO.Message")
    objMessage.From = "myemail.com"
    objMessage.To = "myemail.com"
    objMessage.Subject = " A profile Folder has exceeded 200MB"
    objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "myexchangeserver"
    objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = myport
    objMessage.Configuration.Fields.Update 
      
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder("D:\Profiles")
    
    For Each objSubfolder in objFolder.Subfolders
         If foldersize > objSubfolder > (1024*1024*200) Then
              objMessage.TextBody = "The folder " & objSubfolder & " has exceeded 200MB.  Please panic in an orderly fashion."   
              objMessage.Send
         End If 
    Next 

    Note that most of the scrip only needs to be crated once.  This is faster, more efficient, easier to maintain and easier to understand.

    As Mike pointed out.  Skip VBScript and learn PowerShell.

    Same thing in PowerShell

    dir \users -dir |
         Where{($_|get-childitem -recurse -ea 0|Measure-Object length -sum).Sum -gt 200Mb}|
         ForEach{ Send-MailMessage @props -Body "folder too big $($_,Fullname)"}


    ¯\_(ツ)_/¯


    • Edited by jrv Wednesday, May 28, 2014 3:32 PM
    Wednesday, May 28, 2014 3:32 PM
  • I'll remember the information you pointed out.

    FYI, alot of what I know wasn't learned by rote. It took eight months using home lab equipment and books for me to understand concepts and theories to get my CCNA, so I know exactly what it means to invest time into learning skills. Up until now, I've not had a need to utilize a language, so please don't lump me into the same group as those who don't want to invest the time, it's just that I didn't have the time to invest at this point to implement what the "higher ups" wanted.  

    Wednesday, May 28, 2014 3:46 PM
  • Not lumping you.  I am suggesting that you backtrack and learn about basic computing and logic.  Once you have that down get a book on the basics of programming.  After that things like script will seem more trivial and you will be able to think through the issues as they arise.

    Anyway.  Good luck.


    ¯\_(ツ)_/¯

    Wednesday, May 28, 2014 4:03 PM
  • No offense was taken, once again, Thank You for challenging so that I got the right answer.

    Have a great day and upcoming weekend.

    Wednesday, May 28, 2014 4:07 PM