Компьютерные сети
5
Вклад в тег
$MinimumSize = 10 * 1024 * 1024 * 1024
$InfoArr = Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" | Where { $_.FreeSpace -lt $MinimumSize }
ForEach ($Info in $InfoArr)
{
Write-Host "sending mail"
$mail = New-Object System.Net.Mail.MailMessage
$mail.From = New-Object System.Net.Mail.MailAddress("server@server.net")
$mail.To.Add("admin@server.net")
$mail.Subject = "Недостаточно свободного места.";
$mail.Body = "На сервере server.net на диске " + $Info.DeviceID + " недостаточно свободного места. Осталось: " + "{0:N0}" -f ($Info.FreeSpace / 1024 / 1024) + "Мб"
$smtp = New-Object System.Net.Mail.SmtpClient
$smtp.host = "server.net"
$Credentials = new-object System.Net.networkCredential
$Credentials.domain = "net"
$Credentials.UserName = "admin@server.net"
$Credentials.Password = "password"
$smtp.Credentials = $Credentials
$smtp.Send($mail)
}
$InfoArr = Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computer (Get-Content servers.txt) | Where { $_.FreeSpace -lt $MinimumSize }