Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...it was ingeniously designed and all those clicks were for my own good... and that was even before I got my speedy and useful answer to my tekkie question that I eventually posted..."

Geography

Where in the world do Tek-Tips members come from?

VBS/WMI Newbie, help needed...nearly working Helpful Member! 

1ncubu5 (TechnicalUser)
16 Aug 12 8:35
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.

Quote:


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!

Helpful Member!  guitarzan (Programmer)
16 Aug 12 9:15
Clear your variables before setting them with the next server's information

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") 
   r = ""
   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) 
   p = ""
   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 
1ncubu5 (TechnicalUser)
16 Aug 12 10:54
Ah, silly me. Thanks!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close