By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

script to get the free disk space from all the servers

P: 1
Hi All, I am new to the scritping world but did my best in colloating some information and wirting a script to get the free disk space from all the servers.. The only issue is for the servers on which i do not have access, the script is showing the same data of the previous server.in short "On Error Resume Next" is not working :-(

Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2.  
  3. Set objFSO = CreateObject("Scripting.FileSystemObject")
  4. Set objTextFile = objFSO.OpenTextFile("C:\Documents and Settings\e580631\Desktop\Servers.txt")
  5. Set objWMIService = GetObject("winmgmts:" _
  6.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  7.  
  8. Set colItems = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
  9.  
  10. Do Until objTextFile.AtEndOfStream
  11. strComputer = objTextFile.ReadLine
  12.  
  13. Wscript.Echo "ServerName : " & strComputer
  14.  
  15. For Each objItem in colItems
  16. Wscript.Echo "DeviceID: "& VbTab & ObjItem.Name
  17. Wscript.Echo "Total DiskSpace(IN GB): "& VbTab & Round(objItem.Size /1073741824,2)
  18. Wscript.Echo "Free DiskSpace(IN GB): "& VbTab & Round(objItem.FreeSpace / 1073741824)
  19. Wscript.Echo "Percentage Free: "& VbTab & Round((objItem.FreeSpace / objItem.Size) * 1000)/10
  20. Next
  21. Loop
  22. WSCript.Quit
Kindly Assist.
Mar 25 '12 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,623
You may have to Reset/Assign Variable Values for each iteration of the Loop (Each objItem In colItems), as in:
Expand|Select|Wrap|Line Numbers
  1. Dim strDeviceID As String
  2. Dim varTotalDiskSpace As Variant
  3. Dim varFreeDiskSpace As Variant
  4. Dim varPercentageFree As Variant
Expand|Select|Wrap|Line Numbers
  1. For Each objItem In colItems
  2.   strDeviceID = ""
  3.   varTotalDiskSpace = Null
  4.   varFreeDiskSpace = Null
  5.   varPercentageFree = Null
  6.  
  7.   strDeviceID = objItem.Name
  8.   varTotalDiskSpace = Round(objItem.Size / 1073741824, 2)
  9.   varFreeDiskSpace = Round(objItem.FreeSpace / 1073741824)
  10.   varPercentageFree = Round((objItem.FreeSpace / objItem.Size) * 1000) / 10
  11.  
  12.   Wscript.Echo "DeviceID: " & vbTab & strDeviceID
  13.   Wscript.Echo "Total DiskSpace(IN GB): " & vbTab & varTotalDiskSpace
  14.   Wscript.Echo "Free DiskSpace(IN GB): " & vbTab & varFreeDiskSpace
  15.   Wscript.Echo "Percentage Free: " & vbTab & varPercentageFree
  16. Next
Mar 25 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.