Hi all,
Hope this is the correct forum to post this question...
I have created a script to list server names and free disk space, but I must be doing something wrong with the way it stores the results as during the loop it keeps duplicating, e.g.
I'm sure it's a simple fix for someone... here is the source code.
Thanks in advance!
Hope this is the correct forum to post this question...
I have created a script to list server names and free disk space, but I must be doing something wrong with the way it stores the results as during the loop it keeps duplicating, e.g.
Name: X
Total Physical Memory: 15 GB
Hard Disk Details
DeviceID: C:
FileSystem: NTFS
FreeSpace: 7 GB
Size: 15 GB
DeviceID: E:
FileSystem: NTFS
FreeSpace: 29 GB
Size: 49 GB
Name: X
Total Physical Memory: 15 GB
Name: Y
Total Physical Memory: 15 GB
Hard Disk Details
DeviceID: C:
FileSystem: NTFS
FreeSpace: 7 GB
Size: 15 GB
DeviceID: E:
FileSystem: NTFS
FreeSpace: 29 GB
Size: 49 GB
DeviceID: C:
FileSystem: NTFS
FreeSpace: 5 GB
Size: 15 GB
DeviceID: E:
FileSystem: NTFS
FreeSpace: 46 GB
Size: 49 GB
Name: X
Total Physical Memory: 15 GB
Name: Y
Total Physical Memory: 15 GB
Name: Z
Name: X
Total Physical Memory: 15 GB
Hard Disk Details
DeviceID: C:
FileSystem: NTFS
FreeSpace: 7 GB
Size: 15 GB
DeviceID: E:
FileSystem: NTFS
FreeSpace: 29 GB
Size: 49 GB
Name: X
Total Physical Memory: 15 GB
Name: Y
Total Physical Memory: 15 GB
Hard Disk Details
DeviceID: C:
FileSystem: NTFS
FreeSpace: 7 GB
Size: 15 GB
DeviceID: E:
FileSystem: NTFS
FreeSpace: 29 GB
Size: 49 GB
DeviceID: C:
FileSystem: NTFS
FreeSpace: 5 GB
Size: 15 GB
DeviceID: E:
FileSystem: NTFS
FreeSpace: 46 GB
Size: 49 GB
Name: X
Total Physical Memory: 15 GB
Name: Y
Total Physical Memory: 15 GB
Name: Z
...etc
I'm sure it's a simple fix for someone... here is the source code.
Code:
comps="c:\apps\servers.txt"
Servers="c:\apps\servers.htm"
set fso=createobject("scripting.filesystemobject")
set objComputersTxt=fso.opentextfile(comps,1)
set objServersTxt = fso.OpenTextFile(servers,2,True)
do while not objComputersTxt.atendofstream
strComputer = objComputersTxt.readline
Set objWMIService = GetObject("winmgmts:\\" _
& strComputer& "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystem")
For Each objItem in colItems
r = r & "Name: " & objItem.Name & "</p>"
r = r & "Total Physical Memory: " & Int(objItem.TotalPhysicalMemory /1073741824) & " GB" & "</p>"
Next
objServersTxt.WriteLine(r)
objServersTxt.writeLine("</p>")
objServersTxt.writeLine("Hard Disk Details" & "</p>")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DeviceID = 'C:' or DeviceID = 'E:'",,48)
For Each objItem in colItems
p = p & "DeviceID: " & objItem.DeviceID & "<br>"
p = p & "FileSystem: " & objItem.FileSystem & "<br>"
p = p & "FreeSpace: " & Int(objItem.FreeSpace /1073741824) & " GB" & "<br>"
p = p & "Size: " & Int(objItem.Size /1073741824) & " GB" & "</p>"
Next
objServersTxt.WriteLine(p)
objServersTxt.writeLine("</p>")
Loop
objComputersTxt.close
objServersTxt.close
Thanks in advance!