windows-server-2012-r2 – 如何在Windows Server 2012 R2 Datacenter上创建低磁盘空间警报

前端之家收集整理的这篇文章主要介绍了windows-server-2012-r2 – 如何在Windows Server 2012 R2 Datacenter上创建低磁盘空间警报前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个在Azure中运行的 Windows Server 2012 R2 Datacenter虚拟机.

最近,我的一个磁盘空间不足.

如何在其中一个磁盘驱动器磁盘空间不足时设置通知系统来提醒我?

想到的唯一一件事就是写一个powershell脚本,但我想知道是否有更好的方法来做到这一点,例如通过Windows Server的服务器管理器/仪表板上的东西?我也无法通过Azure看到任何方法.

谢谢!

这就是你要做的事情:

Event ID 2013 (Disk Is At Or Near Capacity) not getting logged

总而言之,请确保在事件日志中记录磁盘空间警报:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters]
"DiskSpaceThreshold"=dword:0000000a
"LowDiskSpaceMinimum"=dword:00000000

(您必须添加这两者,而不仅仅是其中一个.)

然后,您必须将任务附加到事件.这里有一些XML可以导入任务调度程序,将所述任务附加到所述事件:

<?xml version="1.0" encoding="UTF-8"?>
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task" version="1.3">
   <RegistrationInfo>
      <Date>2013-02-05T14:37:17.165247</Date>
      <Author>[YourDomain]\[YourUserName]</Author>
      <Description>Send an emailed warning when a low disk space event is recorded.</Description>
   </RegistrationInfo>
   <Triggers>
      <EventTrigger>
         <Enabled>true</Enabled>
         <Subscription>&amp;lt;QueryList&amp;gt;&amp;lt;Query Id="0" Path="System"&amp;gt;&amp;lt;Select Path="System"&amp;gt;*[System[Provider[@Name='srv'] and EventID=2013]]&amp;lt;/Select&amp;gt;&amp;lt;/Query&amp;gt;&amp;lt;/QueryList&amp;gt;</Subscription>
      </EventTrigger>
   </Triggers>
   <Principals>
      <Principal id="Author">
         <UserId>S-1-5-20</UserId>
         <RunLevel>LeastPrivilege</RunLevel>
      </Principal>
   </Principals>
   <Settings>
      <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
      <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
      <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
      <AllowHardTerminate>true</AllowHardTerminate>
      <StartWhenAvailable>true</StartWhenAvailable>
      <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
      <IdleSettings>
         <StopOnIdleEnd>true</StopOnIdleEnd>
         <RestartOnIdle>false</RestartOnIdle>
      </IdleSettings>
      <AllowStartOnDemand>true</AllowStartOnDemand>
      <Enabled>true</Enabled>
      <Hidden>false</Hidden>
      <RunOnlyIfIdle>false</RunOnlyIfIdle>
      <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
      <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
      <WakeToRun>false</WakeToRun>
      <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
      <Priority>7</Priority>
   </Settings>
   <Actions Context="Author">
      <SendEmail>
         <Server>smtpServer.YourCompany.co.uk</Server>
         <Subject>Low disk space warning on server: [ServerName]</Subject>
         <To>Admin@YourCompany.co.uk</To>
         <From>noreply@YourCompany.co.uk</From>
         <Body>Disk space is running low on server: [ServerName] - please investigate.</Body>
         <HeaderFields />
         <Attachments />
      </SendEmail>
   </Actions>
</Task>

您需要编辑SMTP服务器和其他变量以满足您的需要.这将在您的服务器上发生该事件(磁盘空间不足)时向您发送电子邮件.

值得注意的是,Server 2008,2012等应该自动默认以10%生成此警报,因此除非您需要自定义而不是10%,否则可能无需修改注册表.

或者,您可以使用Powershell进行操作.

$Threshold = 10 #Percent

Foreach($Disk In Get-CimInstance Win32_LogicalDisk | Where DriveType -EQ 3)
{
    $PercentFree = [Math]::Round(($Disk.FreeSpace / $Disk.Size) * 100,1)
    If ($PercentFree -LT $Threshold)
    {
        Send-MailMessage -From $From -To $To -Subject "Low Disk Space on $Servername" -Body "Low Disk Space on $Servername" -SmtpServer $SMTPServer
    }
}

安排并以一定间隔运行它. (我只是嘲笑了我的头脑,但你明白了.)

猜你在找的Windows相关文章