我研究了谷歌并尝试了几种不同的选项,但没有一个提供我正在寻找的结果。此脚本会生成包含我要查找的数据的电子邮件,但无论阈值如何,它都会发送电子邮件。如果我知道我需要更改什么,以便脚本仅在驱动器低于阈值时发送电子邮件,我将不胜感激。
$freeSpaceThreshold = 5GB
#$computerName = "mycomputer"
$drive = "C:"
$driveData = Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter DriveType=3 | Select-Object DeviceID, @{'Name'='Size (GB)'; 'Expression'={[math]::truncate($_.size / 1GB)}}, @{'Name'='Freespace (GB)'; 'Expression'={[math]::truncate($_.freespace / 1GB)}}
if ($driveData.FreeSpace -lt $freeSpaceThreshold)
{
$from = "[email protected]"
$to = "[email protected]"
$subject = "Low Disk Space!"
$body = "Free Space Remaining: " + "$($CDisk.FreeSpace)GB" + " Drive" + $_.deviceid
$smtpServer = "smtp.domain.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($from,$to,$subject,$body)
}