Script for counting number of files in folders RRS feed

  • Question

  • Hey team,

    I'm trying to write a script that will count the number of files in a folder on x2 different servers, and if they number of files exceeds X amount of files then it will report an error.

    I've got the script working for one folder on a server but am wondering if there's a way of adding it all in one script so it checks all the folders on the 2 servers in stead of me writing 10 of these scripts and having 10 different scheduled tasks.

    Any thoughts on adding to my below script?


    strComputer = "MyServerName"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Do While True
    Set colFileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='FolderLocation'} Where " _
    & "ResultClass = CIM_DataFile")
    If colFileList.Count >= 100 Then
    Exit Do
    End If
    Wscript.Sleep 600000
    Wscript.Echo "There are at least 100 log files in the target folder."

    • Moved by Bill_Stewart Friday, July 27, 2018 8:36 PM This is not "scripts on demand"
    Monday, May 21, 2018 8:13 PM

All replies