Hi all,
I need some help with a script. I am trying to write a script that will send out an email when the drive freespace on a Windows server is below 10%. Although it sends out the email and lists the drive that is having a problem, it also lists 2 other internal drives (C: and D and are not below 10%. How do I get rid of the other 2 drives in the email?
See below:
Const Unknown = 0
Const Removable = 1
Const Fixed = 2
Const Remote = 3
Const CDROM = 4
Const RAMDisk = 5
Dim SpaceFree
'
'
' get current computer name (from system environment variables)
Function GetCurrentComputerName
set oWsh = WScript.CreateObject("WScript.Shell")
set oWshSysEnv = oWsh.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
End Function
'====================================================================================
' Begin main code
'====================================================================================
str = ""
set oFs = WScript.CreateObject("Scripting.FileSystemObject")
set oDrives = oFs.Drives
strComputerName = GetCurrentComputerName ' get name only once for performance reasons
for each oDrive in oDrives
Select case oDrive.DriveType
Case Fixed
str = str & strComputerName & " " & oDrive.DriveLetter & " " & Round(oDrive.FreeSpace / oDrive.TotalSize,2) & vbcrlf
If oDrive.FreeSpace / oDrive.TotalSize < .10 Then
Set objEmail = CreateObject ("CDO.Message")
DateInfo = DateInfo & Now & VbCrLf
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery ("Select * FROM Win32_ComputerSystem")
For each objSysInfo in colSettings
UserName = objSysinfo.UserName
Next
objEmail.From = "server name"
objEmail.To = "my email addr "
objEmail.Subject = "Drive Space Report"
ObjEmail.Textbody = "Total drive freespace is less than 10% for the following drive(s), see below " & vbcrlf _
& str & DateInfo
objEmail.Configuration.Fields.Item (" = x
objEmail.Configuration.Fields.Item (" = "xx.xx.x.xx"
objEmail.Configuration.Fields.Item (" = xx
objEmail.Configuration.Fields.Update
objEmail.Send
End If
End Select
next
I need some help with a script. I am trying to write a script that will send out an email when the drive freespace on a Windows server is below 10%. Although it sends out the email and lists the drive that is having a problem, it also lists 2 other internal drives (C: and D and are not below 10%. How do I get rid of the other 2 drives in the email?
See below:
Const Unknown = 0
Const Removable = 1
Const Fixed = 2
Const Remote = 3
Const CDROM = 4
Const RAMDisk = 5
Dim SpaceFree
'
'
' get current computer name (from system environment variables)
Function GetCurrentComputerName
set oWsh = WScript.CreateObject("WScript.Shell")
set oWshSysEnv = oWsh.Environment("PROCESS")
GetCurrentComputerName = oWshSysEnv("COMPUTERNAME")
End Function
'====================================================================================
' Begin main code
'====================================================================================
str = ""
set oFs = WScript.CreateObject("Scripting.FileSystemObject")
set oDrives = oFs.Drives
strComputerName = GetCurrentComputerName ' get name only once for performance reasons
for each oDrive in oDrives
Select case oDrive.DriveType
Case Fixed
str = str & strComputerName & " " & oDrive.DriveLetter & " " & Round(oDrive.FreeSpace / oDrive.TotalSize,2) & vbcrlf
If oDrive.FreeSpace / oDrive.TotalSize < .10 Then
Set objEmail = CreateObject ("CDO.Message")
DateInfo = DateInfo & Now & VbCrLf
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery ("Select * FROM Win32_ComputerSystem")
For each objSysInfo in colSettings
UserName = objSysinfo.UserName
Next
objEmail.From = "server name"
objEmail.To = "my email addr "
objEmail.Subject = "Drive Space Report"
ObjEmail.Textbody = "Total drive freespace is less than 10% for the following drive(s), see below " & vbcrlf _
& str & DateInfo
objEmail.Configuration.Fields.Item (" = x
objEmail.Configuration.Fields.Item (" = "xx.xx.x.xx"
objEmail.Configuration.Fields.Item (" = xx
objEmail.Configuration.Fields.Update
objEmail.Send
End If
End Select
next