2011.02.17 17:15

PowerShell 디스크 체크후 메일발송


#디스크 체크

$drives = gwmi win32_logicaldisk -filter "drivetype=3"
$server = @{n="Server";e={$_.__SERVER}}
$free = @{n="FreeSpace(GB)";e={"{0:N2}" -f ($_.FreeSpace/1GB)}}
$drives | select $server,deviceID,$free | ft -auto | Out-File -FilePath diskuse.txt

#메일발송

$SmtpServer = "127.0.0.1"
$From = "winadmin@hanbiro.com"   #보내는사람
$To =  "winadmin@hanbiro.com"
$subject = "Disk Check"
$filename = "C:Powershelldiskuse.txt"  
$Body = Get-Content -Path .diskuse.htm
$smtp = new-object system.net.mail.smtpClient($SmtpServer)
$mail = new-object System.Net.Mail.MailMessage
$att = new-object System.Net.Mail.Attachment($filename)
$mail.From = $From
$mail.To.Add($To)
$mail.Subject = $subject
$mail.Body = "$Body"
$mail.Attachments.Add($att)
$mail.IsBodyHtml = $false
$smtp.Send($mail)

Trackback 0 Comment 1