The first problem I can see is that your calculated
$now
is not really the date. Yes, this is a bit confusing…
"Today" means that you need to check up if some time is greater of equal the
any time of the same date. This is not what happens in your code. Let me run this code right now:
$date = Get-Date
# printing it:
$date
# and, to compare:
$date.Date
Output:
Tuesday, April 02, 2013 2:06:38 PM
Tuesday, April 02, 2013 12:00:00 AM
Can you see what's going on? In first case, you get not the very beginning of the day, but just the current time. The function
Get-Date
happens to wrap the static property
System.DateTime.Now
(which you can also use); and its name is very confusing.
The correct comparison of the date with the file time can be like this:
$date = Get-Date # now
# same as:
# [System.DateTime]::Now
$date = $date.Date
# ...
$file_time = # file creation time...
# ...
$select = $file_time -ge $date
Now, you can use it in the query like this:
$date = Get-Date # now
$date = $date.Date
$file_array = Get-ChildItem | where { $_.CreationTime.Date -ge $date } # any time today and later
In your final code, you should also apply your logic taking into account the day of week, which you already have.
Pay attention for the sample of the syntax
[System.DateTime]::Now
. This is how you can use almost all power of .NET FCL, and more: you can additionally load extra GAC assemblies, that is, everything else which was installed in GAC on top of .NET FCL, and use it all.
I tested all my code samples…
—SA