I want script that check free space of C drive in multiple computers via set list of IP's.. from text. file
I want the script for windows 7 environment.. and the script should check the free space of C drive, and if is less than 10gb, then it will show me that ip...
I tried with fsutil but this work just in local machine, and I have a lot computers.
Hope some can help me with that.
Create the following files:
computers.txt
computername1
10.40.1.60
You can specify computers name or their ips.
CheckDiskFree.vbs
'
' Check drive c free space
'
On Error Resume Next
Const MIN_FREE = 10 ' Gb
Const ForAppending = 8
Const HARD_DISK = 3
Const ForReading = 1
CONST ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set SrvList = objFSO.OpenTextFile("computers.txt", ForReading)
Set oShell = CreateObject("WScript.Shell")
Set ReportFile = objFSO.OpenTextFile ("FreeSpaceReport.csv", ForAppending, True)
'
' Report headers
'
ReportFile.writeline "Computer" & vbTAB & "Drive C Free (Gb)" & vbTAB & "Status"
'
' Loop
'
Do Until SrvList.AtEndOfStream
StrComputer = SrvList.Readline
wscript.echo now & vbTAB & StrComputer
If Not IsConnectible(strComputer, "", "") Then
ReportFile.writeline(strComputer & vbTAB & " no available")
Else
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & " AND DeviceID = 'C:' ")
For Each objDisk in colDisks
FreeGB = objDisk.FreeSpace / (1024 * 1024 * 1024)
strStatus = "ok"
If FreeGB < MIN_FREE Then strStatus = "Low disk"
ReportFile.writeline(strComputer & vbTAB & Round(FreeGB,2) & vbTAB & strStatus)
Next
End If
Loop
'
Wscript.Quit
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 7, 2) & "/" & _
Mid(dtmBootup, 5, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
13, 2))
End Function
Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim sTempFile, fFile
If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750
sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName
oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO & " " & sHost & ">" & sTempFile, 0 , True
Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII)
Select Case InStr(fFile.ReadAll, "TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select
fFile.Close
objFSO.DeleteFile(sTempFile)
End Function
To run script you must execute the following command: cscript CheckDiskFree.vbs
The script will create FreeSpaceReport.csv with the results.