Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

What is the free space a machine is having in the file

Hi,

I have a file which has all the machine names .Is there a way to find the free space a machine is available with. On all the drives available in the machine.

Regards
Sharath
Avatar of davidrivers
davidrivers

Probally not from the hostname; if the machines have Windows XP or Have the terminal services client / remote administration then you could logon as the domain administrator or a local administrator and manually check each machine.

The other option would require asset software to be installed on the client machines.

Please provide further information are all machines running WIndows XP and are they on a Domain? If they are then I can come up with a solution via installed software and running it via a logon script
You really need SMS from what I can tell based on all the questions you have been asking.
Avatar of bsharath

ASKER

chuckyh:

General Question.

Have you installed SMS.Is it very touch to set it up.I am planning to install but wanted an expert to give me some suggestions to my Questions before i get started...
I do agree that you should be looking at some form of system & Asset management software.

Having said that what you want is possible.

The following WMI script if run on a local computer will give you the drive name for all local hard drives and the ammount of free space on each.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colDiskDrives = objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk Where " _
        & "Name <> '_Total'")

For Each objDiskDrive in colDiskDrives
    Wscript.Echo "Drive Name: " & objDiskDrive.Name
    Wscript.Echo "Free Space: " & objDiskDrive.FreeMegabytes
Next


If you change strComputer = "." to be a remote computers name then it will report on that.

So all you now need to do is read each machine name from a file and use the machine name as StrComputer. Also need to point the script to a results.txt file and write the results to that rather then just wscript.echo. You may be able to modify other scripts you have to acheive that. If you can not then shout and I will try write it for you but That may not be for a couple of days.

hope it helps
Avatar of Gastone Canali

' get-free-space-all-PCs.vbs
' read the computer computers list from the file c:\computers.txt
' for get output on file run:
' cscript //nologo get-free-space-all-PCs.vbs >result.txt
'
'
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Computers.txt", ForReading)
do while not objFile.AtEndOfStream
    PC = objFile.ReadLine
    Gethdinfo (PC)
loop
objFile.Close
sub Gethdinfo(strComputer)
  getinfo=""
  On Error Resume Next
  Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/CIMV2" )
  Set colInstances = objWMIService.ExecQuery( "SELECT * FROM Win32_LogicalDisk where driveType=3",  "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )
  If Err.Number = 0 then
    For Each objInstance In colInstances
          getinfo=getinfo & " " & objInstance.deviceID &" " & objInstance.FreeSpace
    Next
  else
    getinfo="Error computer not found"
    err.clear
  end if
  WScript.echo strComputer & space(10-len(strComputer)) &": " & getinfo
end sub
'
' get-free-space-all-PCs.vbs
' read the computer computers list from the file c:\computers.txt
' for get output on file run:
' cscript //nologo get-free-space-all-PCs.vbs >result.txt
' with output in megabytes
'
Const ForReading = 1
Const CONVERSION_FACTOR = 1048576
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Computers.txt", ForReading)
do while not objFile.AtEndOfStream
    PC = objFile.ReadLine
    Gethdinfo (PC)
loop
objFile.Close
sub Gethdinfo(strComputer)
  getinfo=""
  On Error Resume Next
  Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/CIMV2" )
  Set colInstances = objWMIService.ExecQuery( "SELECT * FROM Win32_LogicalDisk where driveType=3",  "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )
  If Err.Number = 0 then
    For Each objInstance In colInstances
          getinfo=getinfo & " " & objInstance.deviceID &" " & round(objInstance.FreeSpace/conversion_factor,0) &" MB"
    Next
  else
    getinfo="Error computer not found"
    err.clear
  end if
  WScript.echo strComputer & space(10-len(strComputer)) &": " & getinfo
end sub
I get this.

hydsophos :  C: 8414646784 D: 80750157824
Can you change the output as 20 GB.Is this showing free space ?
Thanks ....
When it is GB can it show GB instead of MB
ASKER CERTIFIED SOLUTION
Avatar of Gastone Canali
Gastone Canali
Flag of Italy 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