On Error Resume Next
Dim FSO, Diskdriver,dd,showfreespace,totalsizespace,sizepercent
Dim sendmailpermission
sendmailpermission = 0
Set FSO = WScript.CreateObject ("Scripting.FileSystemObject")
If (fso.folderexists ("C:\Disk2")) = False Then
Set Foldr=fso.createfolder ("C:\Disk2")
End if
Set tf = fso. CreateTextFile ("C:\Disk2\DiskSpacelog.txt", True)
Set Drivers = fso. Drives
For each diskdriver in Drivers
' List all drives in the computer
DD = Diskdriver.driveletter
Set DRV = fso. Getdrive (DD & ":")
S=drv. DriveType
If s = 2 and DD <> "Q" Then
Showfreespace = DD & "Local Disk free Space is" & FormatNumber (DRV. freespace/1024/1024/1024,1) & "GB"
' WScript.Echo Showfreespace
Tf. WriteLine Showfreespace
Totalsizespace = DD & "Local Disk total Size is" & FormatNumber (DRV. totalsize/1024/1024/1024,1) & "GB"
' WScript.Echo Totalsizespace
' TF. WriteLine Totalsizespace
Sizepercentnumber= DRV. Freespace/drv. TotalSize * 100
Sizepercent = "Free Space Size Percent" & FormatNumber (DRV. Freespace/drv. TotalSize * 100,2) & "%"
' WScript.Echo sizepercent
Tf. WriteLine sizepercent
Tf. WriteLine "=================================="
Showfreespace = Null
Totalsizespace = Null
Sizepercent = Null
If Sizepercentnumber < Then
Sendmailpermission = 1
End If
End If
Next
MyDate = "Checking date is" & Date
Tf. WriteLine mydate
Tf. Close ()
If sendmailpermission = 1 Then
Sendmailresult=sendmail ("[Email protected]", "Welcome1", "[email protected]", "Warning:low free Disk Space on Srv10101", "Warning:free disk space is less than 11% on SRV10101!!!", "C:\disk2\DiskSpacelog.txt")
' Sendmailresult=sendmail ("[Email protected]", "Welcome1", "[email protected]", "Srv10101 Disk Space Checking", "Warning : Srv10101 has low free disk space!!! "," C:\disk2\DiskSpacelog.txt ")
End If
Function SendMail (sendfrom,password,sendto,mailtopic,mailbody,mailattachment)
On Error Resume Next
Ms_space = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject ("CDO. Message ")
Email.BodyPart.Charset = "GBK"
Email.from = Sendfrom
Email.to = SendTo
Email.subject = Mailtopic
Email.htmlbody = Mailbody
If mailattachment <> "Then
For i=0 to Ubound (Split (MailAttachment, ";"))
Email.addattachment Split (MailAttachment, ";") (i)
Next
End If
With Email.Configuration.Fields
. Item (ms_space& "sendusing") = 2
. Item (ms_space& "smtpserver") = "smtp." &split (Sendfrom, "@", -1, vbTextCompare) (1)
. Item (ms_space& "smtpserverport") = 25
. Item (ms_space& "smtpauthenticate") = 1
. Item (ms_space& "Sendusername") =split (Sendfrom, "@", -1,vbtextcompare) (0)
. Item (ms_space& "sendpassword") = Password
. Update
End with
Err.Clear
Email.send
If Err.number<>0 Then
Sendmail=false
Else
Sendmail=true
End If
Set email=nothing
End Function
This article from the "Erick" blog, declined to reprint!
Disk Space Checking