We have an application that has a temporary folder where files reside before
being processed. We know there is an issue if the files exist in this directory
for a lengthy period of time. Some of these files come from outside locations,
so we can’t use “Date Modified” as they will sometimes already be >30mins old
when they arrive in this temporary directory. So we want to alert when files
exist for longer than 30mins in the temporary directory. I was attempting to
use the below command, but it’s not behaving as I would expect.
(Get-ChildItem $directory | Where-Object {$_.CreationTime -ge
(Get-Date).AddMinutes(-30)} | Measure-Object).Count
That command returns a count of “0” even though the file has existed for
>30mins (over 180mins at this point). When I get the properties of the file, it
lists the creation date in the following format:
Name : Dummy_File.txt
Length : 5801
CreationTime : 4/23/2015 8:53:48 AM
LastWriteTime : 1/20/2015 9:48:12 PM
LastAccessTime : 4/23/2015 8:53:48 AM
I am wondering if the time comparison doesn’t work how I envision it working.
When I switch to using “-le” the same thing happens, except it constantly
returns “1”.
The end goal is to wrap this in a Management Pack and alert via SCOM, but the
manual execution is not returning accurate results. Do I have to format the
date/time differently in order to perform a proper calculation?
Thank you.
-Geoff
Confidentiality Notice: This is a transmission from Community Hospital of the
Monterey Peninsula. This message and any attached documents may be confidential
and contain information protected by state and federal medical privacy
statutes. They are intended only for the use of the addressee. If you are not
the intended recipient, any disclosure, copying, or distribution of this
information is strictly prohibited. If you received this transmission in error,
please accept our apologies and notify the sender. Thank you.
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1