-
Notifications
You must be signed in to change notification settings - Fork 0
/
freespace.vbs
83 lines (56 loc) · 1.88 KB
/
freespace.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Option Explicit
Dim objFSO 'File System Object
Dim objDrive 'Drive Object
Dim lngSpace
Dim WshShell 'Shell Commander
Dim drive
Dim Threshold
Dim oArgs, ArgNum
'Scripted by Deon van Zyl
'Read Commandline
Set oArgs = WScript.Arguments
ArgNum = 0
drive = UCase(oArgs(ArgNum))
'Set Objects
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
select case drive 'Set for Drive cannot be done through a Var
case "C"
Set objDrive = objFSO.Drives.Item("C")
Threshold = 2000000000 '2 GIG
case "E"
Set objDrive = objFSO.Drives.Item("E")
Threshold = 20000000000 '20 GIG
case "G"
Set objDrive = objFSO.Drives.Item("G")
Threshold = 20000000000 '20 GIG
case Else:
Set objDrive = objFSO.Drives.Item("C")
Threshold = 2000000000 '2 GIG
end select
If objDrive.IsReady = True Then
lngSpace = objDrive.FreeSpace
'msgbox lngSpace
If lngSpace < Threshold Then
'Convert from Bytes to MB
lngSpace = FormatNumber((lngSpace / 1024) / 1024 ,2)
'-----------Create msg.txt (body of email-----)
Dim objFileSystem, objOutputFile
Dim strOutputFile
' generate a filename base on the script name
strOutputFile = "msg.txt"
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
objOutputFile.WriteLine("Freespace = " & lngSpace & " Gig on " & drive & ": at " & Now )
objOutputFile.WriteLine("Please inform the Websystems Team of this email on ext. 1633 ASAP.")
objOutputFile.Close
Set objFileSystem = Nothing
'-----------------------------
WshShell.Run "mailsend.bat" 'Drive is Low on Disk Space !! Will send a email notification
'msgbox "freespace =" & lngSpace
End if
End If
'Clear Environment
On Error Resume Next
Set objFSO = Nothing
Set objDrive = Nothing