Restart computer if…

I like to find new needs to fill… Once again, I found one today on LinkedIn: Sambasiva Rao K. asked for some help on the “PowerShell Power Users” LinkedIn discussion group:

I have a requirement where i wanted to monitor the last modified time of a .MDB file and compare it with local system time and if it differences more than 1hour, i want my system to be restarted.

So, here we are:

$TestFile=Get-ChildItem -Path MyFile.mbd | Where {(!($_.PSIsContainer)) -and ($_.LastWriteTime -gt ((Get-Date).AddHours(-1)))}
if ($TestFile) {Write-Host "Restarting now..." ; Restart-Computer} else {Write-Host "Nothing to do..."}

Has to be scheduled, each 30 minutes for example (obviously less than an hour…).
http://www.zerrouki.com/schedule-a-powershell-script-execution/

Leave a Reply

Scroll to Top