Last active
May 4, 2017 14:08
-
-
Save neodigm/7d816c746c0c18a61923126606baf7a9 to your computer and use it in GitHub Desktop.
This PowerShell script will remove files, if they are older than one hour and if the Scheduled task is NOT running, and if the Scheduled task has not updated it log in the past two minutes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 20160601 Scott C. Krause | |
# This PowerShell script will remove files, if they are older than one hour and if the Scheduled task is NOT running, and if the Scheduled task has not updated it log in the past two minutes. | |
Set-ExecutionPolicy Bypass | |
# popu var if compr proc is not busy | |
$recent_logged = Get-Item C:\ltd_auto_image\logs\ltd_auto_image.txt | where-object {(new-timespan $_.LastWriteTime).minutes -ge 16} | |
if ($recent_logged) { | |
# if sched task / compr proc is state running del | |
$ltd_auto_running = Get-ScheduledTask -TaskName ltd_auto_image | Where State -eq "Running" | |
#if ($recent_logged) { | |
$myFolder = 'C:\ltd_auto_image\images_product\images_in\' | |
$filesToDelete = Get-ChildItem -Path $myFolder | Where-Object {$_.PSIsContainer -eq $false -and $_.LastWriteTime -lt $(Get-Date).AddHours(-1)} | |
$filesToDelete | Remove-Item -Force | |
$myFolder_s = 'C:\ltd_auto_image\images_static\images_in\' | |
$filesToDelete_s = Get-ChildItem -Path $myFolder_s | Where-Object {$_.PSIsContainer -eq $false -and $_.LastWriteTime -lt $(Get-Date).AddHours(-1)} | |
$filesToDelete_s | Remove-Item -Force | |
#} Else { | |
# Exec failsafe | |
#} | |
} | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
20160601 Scott C. Krause
This PowerShell script will remove files, if they are older than one hour and if the Scheduled task is NOT running, and if the Scheduled task has not updated it log in the past two minutes.