Difference between revisions of "User:Mjb/Make Windows report disk failures"
Line 7: | Line 7: | ||
I figure once a day is good enough; what are the odds that both drives would fail on the same day? Don't answer that. | I figure once a day is good enough; what are the odds that both drives would fail on the same day? Don't answer that. | ||
− | All that does, though, is make an event in the System log. Another task | + | All that does, though, is make an event in the System log. Another task needs to be triggered by that event in order to send a notification to the desktop. |
I set them up in Task Scheduler, but I think you can also do it by installing the XML code (below) with the following command (replacing <code>''xmlfile.xml''</code> with the actual file name, of course): | I set them up in Task Scheduler, but I think you can also do it by installing the XML code (below) with the following command (replacing <code>''xmlfile.xml''</code> with the actual file name, of course): |
Revision as of 20:29, 21 January 2015
After setting up mirrored drives (software RAID) in Disk Manager, I wondered what would happen if a mirrored drive failed. I mean, aside from the other drive continuing to work, would I be notified that one of the drives needs to be replaced? It appears the answer is no!
So I used the Task Scheduler to make a task that periodically runs this command (as an argument to cmd.exe /C
):
echo list volume | diskpart | findstr /i "failed risk" && eventcreate /l "System" /so "Disk Check Script" /id 1 /t WARNING /d "A drive has failed. Check Disk Manager."
I figure once a day is good enough; what are the odds that both drives would fail on the same day? Don't answer that.
All that does, though, is make an event in the System log. Another task needs to be triggered by that event in order to send a notification to the desktop.
I set them up in Task Scheduler, but I think you can also do it by installing the XML code (below) with the following command (replacing xmlfile.xml
with the actual file name, of course):
schtasks /create /xml "xmlfile.xml"
You should replace XXX
and YYY
in these examples with a valid machine name and user name, although I'm not sure if anything in the RegistrationInfo section really matters. (If it doesn't work, try just removing the whole RegistrationInfo element and its contents, or replacing it with an empty element, like this: <RegistrationInfo/>
.)
Report disk failures in System log.xml
<?xml version="1.0" encoding="UTF-16"?> <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2015-01-21T19:36:03.4744179</Date> <Author>XXX\YYY</Author> <Description>If any drives are "at risk" or "failed", add an event to the System log</Description> </RegistrationInfo> <Triggers> <CalendarTrigger> <StartBoundary>2015-01-21T19:45:00</StartBoundary> <Enabled>true</Enabled> <ScheduleByDay> <DaysInterval>1</DaysInterval> </ScheduleByDay> </CalendarTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>S-1-5-18</UserId> <RunLevel>LeastPrivilege</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</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>P3D</ExecutionTimeLimit> <Priority>7</Priority> </Settings> <Actions Context="Author"> <Exec> <Command>cmd.exe</Command> <Arguments>/C "echo list volume | diskpart | findstr /i "failed risk" && eventcreate /l "System" /so "Disk Check Script" /id 1 /t WARNING /d "A drive has failed. Check Disk Manager.""</Arguments> </Exec> </Actions> </Task>
Alert the user in the event of a disk problem.xml
<?xml version="1.0" encoding="UTF-16"?> <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> <RegistrationInfo> <Date>2015-01-21T19:51:16.8376592</Date> <Author>XXX\YYY</Author> <Description>Display a message on the Desktop to alert the user when the System log contains a disk problem as reported by the "Report disk failures in System log" task</Description> </RegistrationInfo> <Triggers> <EventTrigger> <Enabled>true</Enabled> <Subscription><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='Disk Check Script'] and EventID=1]]</Select></Query></QueryList></Subscription> </EventTrigger> </Triggers> <Principals> <Principal id="Author"> <UserId>S-1-5-18</UserId> <RunLevel>LeastPrivilege</RunLevel> </Principal> </Principals> <Settings> <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> <StopIfGoingOnBatteries>true</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> <RestartOnFailure> <Interval>PT5M</Interval> <Count>3</Count> </RestartOnFailure> </Settings> <Actions Context="Author"> <ShowMessage> <Title>Disk check script (scheduled task)</Title> <Body>It looks like a disk drive has reported "at risk" or "failed". Please check the Disk Manager ASAP!</Body> </ShowMessage> </Actions> </Task>