Verification in order to see if one or several files exist after a given time and possibility to take action in regards to to the result.
The script is in PowerShell and is listing files that are aged more than X minutes fro the actual time and is returning the filename and the creation time. In order to make the script run either you copy and paste the content in a PowerShell prompt or you create a .PS1 file and you launch the script like this :
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file c:\MyDirectory\MyScript.PS1
- The script creates a variable in which we set the result of the command.
- The command returns the files in the directory indicated in which the files have a creation time smaller than the actual time less the defined delay.
- Example : My file has been created at 10:29 and it is 11:00 while I'm checking. So, 11:00 - 00:30 = 10:30 and 10:29 is smaller than 10:30 then my file will be included in the result.
- A verification with a simple "If - Else" if you want to perform any action depending the result.
- Finally, you get the command result in order to see if it is null or not and the script returns the value if any.
$result = Get-ChildItem c:\myTargetDir | where{$_.CreationTime -le (Get-Date).AddMinutes(-30)} | select Name,CreationTime
if($result -eq $null)
{ $value = 0}
else
{$value = 1}
$value
$result