伺服器硬碟空間小於百分之10的情況下,自動化的發出警告mail
透過下面的PowerShell指令
設定為只要有硬碟空間小於百分之10的情況下,以SMTP Server寄信通知收件者
指令如下
$mythreshold = 10
$freespace = gwmi Win32_LogicalDisk -Filter "DriveType=3" | select Name, FileSystem,FreeSpace,BlockSize,Size
ForEach($item in $freespace)
{
$item.BlockSize=(($item.FreeSpace)/($item.Size))*100
$item.FreeSpace=($item.FreeSpace/1GB)
$item.Size=($item.Size/1GB)
if ($item.BlockSize -lt $mythreshold){
$from = "ithelp@athentek.com"
$to = "ithelp@miniasp.com"
$subject = "Low Disk Space!"
$body = "Free Space Remaining: " + "<p></p>磁碟總容量(GB):" + $item.size + "<p></p>剩餘空間(GB):" + $item.FreeSpace + "<p></p>磁區:" + $item.name + "<p></p>剩餘百分比:" + $item.BlockSize +"%"
$smtpServer = "192.168.2.3"
Send-MailMessage -From $from -to $to -Subject $subject -Body $body -SmtpServer $smtpServer -BodyAsHtml -Encoding UTF8
}
}