Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP! FSO giving me fits

Status
Not open for further replies.

samuelma

MIS
Jun 5, 2001
16
0
0
US
First I should say, I've tried to do this and I just don't get it. I'm not a programmer, I'm just an administrative person that has been tasked with something totaly new and unknown. (Programming VBScript.) I've done a little html code for simple things but this is overwhelming.

I've been asked to give the amount of free disk space on all the server computers in the form of a report. That's 63 server computers.

I figured out how to get the drive space from remote computers in pop up windows (with help). I keep changeing the server computer name in the VBScript to get each server computers free disk space. I've been doing this for about a month. (This works but takes a long time.)
Code:
Const HARD_DISK = 3
strComputer = "print1"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
    Wscript.Echo "Drive: "& vbTab &  objDisk.DeviceID	 
    Wscript.Echo "Free Space: "& vbTab & objDisk.FreeSpace
Next


I learned to create a text file in VBScript then write to the same file and save it.
Code:
"creatfile.vbs"
Dim fso, crfile
set fso = CreateObject("Scripting.FileSystemObject")
set crfile=fso.CreateTextFile("c:\samsvbs\test.txt")

"writefile.vbs"
Const ForWriting=2
Dim fso, wrfile
Set fso=CreateObject("scripting.FileSystemObject")
Set wrfile=fso.OpenTextFile("c:\samsvbs\test.txt",ForWriting)
wrfile.Write("This worked")
wrfile.Close

"create-write-file.bat"
createfile.vbs
writefile.vbs
I know a file can be used as a list with all the server computer names in it and that it can be processed to get each server computers free disk space.
I know a file with the output can be created and saved.
I just can't get from Point A ---> B.

I've been working on this for a week in my spare time both at home and at work. I really need to spend less time doing this task every day. I know I should just keep working at it but I don't get how to put the parts together.

 
samuelma,


Dim fso, wrfile
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set fso = CreateObject("scripting.FileSystemObject")

' First open an output file
filename = "c:\samsvbs\test.txt"
Set wrfile = fso_OpenTextFile( filename, ForAppending)
'
' Get the remote machine info
Const HARD_DISK = 3
strComputer = "print1"
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")

For Each objDisk in colDisks
wrfile.writeline "Drive: "& vbTab & _
objDisk.DeviceID & vbTab & _
"Free Space: "& vbTab & objDisk.FreeSpace
Next

' Close the file
wrfile.close

fengshui_1998






 
Thank You!!!
I was able to take what you gave me and make it read a file with multiple server names in it! This is the code...
THANKS AGAIN!

Code:
Dim fso, wrfile
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const HardDisk = 3

Set fso = CreateObject("scripting.FileSystemObject")
' First open an output file
filename = "c:\samsvbs\test.txt"
Set wrfile = fso.OpenTextFile( filename, ForAppending)
'Second open an input file
ifilename="c:\samsvbs\srvlst.txt"
Set  rdfile=fso.openTextFile(ifilename, ForReading)
'Read server name from file

do while rdfile.AtEndofStream=false
servername =rdfile.readline()
' Get the remote machine info

strComputer = servername
Set objWMIService = GetObject("winmgmts:" & _
      "{impersonationLevel=impersonate}!\\" & _
      strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & 3 & "")
    wrfile.writeline strComputer
For Each objDisk in colDisks
    wrfile.writeline "Drive: "& vbTab & _
           objDisk.DeviceID & vbTab & _ 
           "Free Space [MB]:  "& vbTab & objDisk.FreeSpace
Next
loop
' Close the file
  wrfile.close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top