Powershell 磁盘使用空间监控,并使用dbmail发送邮件

Powershell 磁盘使用空间监控,并使用dbmail发送邮件
$server = "(local)"
$uid = "sa"
$db="master"
$pwd="fanzhouqi"
$mailprfname = "sina"
$recipients = "XXXX@qq.com"
$subject = 'disk usage monitor'
function sendmail($message)
{
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection 
    $CnnString ="Server = $server; Database = $db;User Id = $uid; Password = $pwd" 
    $SqlConnection.ConnectionString = $CnnString 
    $CC = $SqlConnection.CreateCommand(); 
    if (-not ($SqlConnection.State -like "Open")) { $SqlConnection.Open() } 
    
    $cc.CommandText=" EXEC msdb..sp_send_dbmail 
            @profile_name  = '$mailprfname'
            ,@recipients = '$recipients'
            ,@body = '$message'
            ,@subject = '$subject'
" 
    $cc.ExecuteNonQuery()|out-null 
    $SqlConnection.Close();
}

$output = Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName . |  Format-Table deviceid,@{Label="free(GB)"; Expression={$_.freespace/1024/1024/1024}},@{Label="size(GB)"; Expression={$_.size/1024/1024/1024}} -AutoSize | Out-String
sendmail $output
Powershell 磁盘使用空间监控,并使用dbmail发送邮件

并创建计划任务执行:

bat 脚本 powershell.exe -File "F:\Disk Usage Monitor.ps1" -nointeractive




    本文转自 Fanr_Zh 博客园博客,原文链接:http://www.cnblogs.com/Amaranthus/archive/2012/06/05/2536296.html,如需转载请自行联系原作者




上一篇:项目管理软件选择:redmine or JIRA


下一篇:阿里云acp认证考试时间 阿里云ACP认证考试注意事项有哪些?