Listing 1: Main Code Block in RecycleBinInfo.vbs Public strcomputer, DRS, MasterComputerSIDSource, FileString, DomName On Error Resume Next CONST ForReading = 1 MasterComputerSIDSource = "DomainControllerName" RecyclerServerList = "C:\Temp\RecyclerMasterList.txt" FileString = "C:\Temp\DRS-" & MasterComputerSIDSource & "-SID.xml" Set objNet = CreateObject("WScript.Network") DomName = objNet.UserDomain Set objNet = nothing Call OpenXML ' ******* BEGIN CALLOUT A ******* Set fso = CreateObject("Scripting.FileSystemObject") Set ServerListfile = fso.OpenTextFile(RecyclerServerList,ForReading,False) If Err.Number <> 0 Then DRS.Close MsgBox "ERROR..... Check for correct text filename within VBScript" WScript.Quit Else MsgBox "Press OK to begin Process.... " & vbcrlf & _ "Spreadsheet will appear when process is complete." & vbcrlf & _ "Depending on the number of servers in your list" & vbcrlf & _ "this could take a while to finish." End If ' ******* END CALLOUT A ******* Set XL = CreateObject("Excel.Application") XL.WorkBooks.Add XL.Cells(1,1).Value = "Computer" XL.Cells(1,2).Value = "SID" XL.Cells(1,3).Value = "RecyclerBin Size(Mb)" XL.Cells(1,4).Value = "User" XL.Cells(1,5).Value = "Drive FreeSpace(Mb)" Row = 2 SrvList = ServerListfile.ReadAll ServerListfile.Close aray = Split(SrvList,VBCRLF) ' ####### Main Processing Section ####### For Each arItem In aray Err.Clear If Trim(arItem) <> "" Then strcomputer = "" strcomputer = Trim(arItem) Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") If Err.Number <> 0 Then Err.Clear Else ' ******* BEGIN CALLOUT B ******* Set OSItems = objWMIService.ExecQuery("SELECT Version from Win32_OperatingSystem",,48) For Each OpSys in OSItems OS = OpSys.Version Next Set OSItems = nothing MajorOSVer = clng(left(OS,(instr(OS,".")-1))) ' ******* END CALLOUT B ******* ' ******* BEGIN CALLOUT C ******* Set DriveItems = objWMIService.ExecQuery _ ("SELECT * from Win32_LogicalDisk WHERE DriveType='3'",,48) For Each Drive In DriveItems Drv = trim(Drive.Deviceid) ' ******* END CALLOUT C ******* ' ******* BEGIN CALLOUT D ******* If MajorOSVer > 5 Then Set colSubfolders = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='" & drv & "\$recycle.bin'} " _ & "WHERE AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent") Else Set colSubfolders = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='" & drv & "\recycler'} " _ & "WHERE AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent") End If ' ******* END CALLOUT D ******* ' ******* BEGIN CALLOUT E ******* For Each objFolder in colSubfolders XL.Cells(Row,1).Value = strcomputer XL.Cells(Row,2).Value = objFolder.name XL.Cells(Row,3).Value = GetFolderSize(objFolder.name) XL.Cells(Row,4).Value = _ FindSID(right(objFolder.name,len(objFolder.name)-instrrev(objFolder.name,"\"))) XL.Cells(Row,5).Value = getfreespace(strComputer,drv) Row = Row + 1 Next ' ******* END CALLOUT E ******* Next End If End If Next ' ####### End of Main Processing Section ####### Call closeit XL.Cells.EntireColumn.AutoFit XL.Visible = TRUE MsgBox "Done"