strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk where DeviceID='c:'",,48)
For Each objItem in colItems
If len(objItem.VolumeName)>0 then
TotalSize = CDbl(objItem.Size)/1024/1024/1024
FreeSpace = CDbl(objItem.FreeSpace)/1024/1024/1024
OccupiedSpace = CDbl(objItem.Size - objItem.FreeSpace)/1024/1024/1024
DiskStatus = "-----------------------------------" & vbCrLf _
& "Volume Name:" & vbTab & objItem.VolumeName & vbCrLf _
& "-----------------------------------" & vbCrLf _
& "Total Size of the Disk:" & vbTab & vbTab _
& FormatNumber(TotalSize) & " GB" & vbCrLf _
& "FreeSpace:" & vbTab & vbTab & vbTab _
& FormatNumber(FreeSpace) & " GB (" & round(((FreeSpace/TotalSize) * 100),2) & "%)" & vbCrLf _
& "Occupied Space:" & vbTab & vbTab & vbTab _
& FormatNumber(OccupiedSpace) & " GB (" & round(((OccupiedSpace/TotalSize) * 100),2) & "%)"
Wscript.Echo DiskStatus
end if
Wscript.Echo "-----------------------------------"
Response = MsgBox("Do you wish to send the disk status via Email?", vbYesNo)
If Response = vbYes Then
Wscript.Echo "Sending Email..... "
GenerateEmail DiskStatus
Wscript.Echo "Email Sent Out!"
End If
Wscript.Echo "Checking disk usage limits......"
IF (OccupiedSpace/TotalSize) * 100 > 75 Then
HandleOverUsage OccupiedSpace
Else
Wscript.Echo "Disk Usage under limits."
End If
Next
Function GenerateEmail(ByVal PassedDiskStatus)
Set MyEmail=CreateObject("CDO.Message")
MyEmail.Subject="Subject"
MyEmail.From="name@domain.com"
MyEmail.To="recipient@domain.com"
MyEmail.TextBody=PassedDiskStatus
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'SMTP Server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
'SMTP Port
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
MyEmail.Configuration.Fields.Update
MyEmail.Send
set MyEmail=nothing
End Function
Function HandleOverUsage(ByVal OccupiedSpace)
Wscript.Echo "Disk Usage exceeded 75%. "
End Function
-----------------------------------
Volume Name: OS
-----------------------------------
Total Size of the Disk: 465.17 GB
FreeSpace: 270.60 GB (58.17%)
Occupied Space: 194.57 GB (41.83%)
Do you need help with the code you've written so far?
Does this have to be VBScript, or can it be written in Powershell?
If you are looking for professional help, please look at the list of top VBScript experts to see if they have enabled their Hire Me link.