Link to home
Start Free TrialLog in
Avatar of sydneyithelpdesk
sydneyithelpdesk

asked on

Script to find out size of specific folders from a list of servers

We need to find the size of two folders from a list of file servers. The problem is they may me mounted on any of the volume on the servers. So no consistency as such.
Only thing that is consistent is the names of two folders.
Example- on all 100 file servers  we need to list size of A and B which are sub folders under shared drive  C  and C is on  a volume (volume name may be anything).

Powershell or VBscript anything can work for me.
Avatar of sydneyithelpdesk
sydneyithelpdesk

ASKER

Making this bit easy - C is a shared folder and accessible from any computer so we can forget about which volume it resides on.
Avatar of RobSampson
Hi, give this script a shot.

Regards,

Rob,

strInputFile = "servers.txt"
strOutputFile = "foldersize.csv"
strFolderShare = "C$"
arrSubFolders = Array("Temp", "Users")

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInputFile, ForReading, True)
Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
objOutput.WriteLine """Server"",""" & Join(arrSubFolders, """,""") & """"
While Not objInput.AtEndOfStream
	strComputer = Trim(objInput.ReadLine)
	If strComputer <> "" Then
		If Ping(strComputer) = True Then
			objOutput.Write """" & strComputer & """"
			For Each strSubFolder In arrSubFolders
				strFolderPath = "\\" & strComputer & "\" & strFolderShare & "\" & strSubFolder
				If objFSO.FolderExists(strFolderPath) = False Then
					objOutput.Write ",""<NOT FOUND>"""
				Else
					On Error Resume Next
					Err.Clear
					strSize = 0
					Set objFolder = Nothing
					Set objFolder = objFSO.GetFolder(strFolderPath)
					If Err.Number = 0 Then
						strSize = objFolder.Size/1024/1024
						If Err.Number = 0 Then
							objOutput.Write ",""" & strSize & """"
						Else
							objOutput.Write ",""" & Err.Number & ": " & Err.Description & """"
						End If
					Else
						objOutput.Write ",""" & Err.Number & ": " & Err.Description & """"
					End If
					Err.Clear
					On Error Goto 0
				End If
			Next
			objOutput.WriteLine
		Else
			objOutput.WriteLine """" & strComputer & """<OFFLINE>"",""<OFFLINE>"""
		End If
	End If
Wend
objInput.Close
objOutput.Close

WScript.Echo "Done"

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

Thanks Rob! I was already following one of your article
https://www.experts-exchange.com/questions/27989367/Script-to-find-out-size-of-specific-folders-from-a-list-of-servers.html?anchorAnswerId=38758294#a38758294

Here If i try to run this script Result says "Not found"

I changed third line to "Ndrive$" however as it is a shared folder on every server does this require $ with it.
SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial