1

I'm looking for a script that gives a list of files that are modified in a date range (from 00.00 yesterday to 23.59 yesterday) but the list is empty.

Here the script:

$today = Get-Date
$yesterday = $today.AddDays(-1)
$today00 = $today | Get-Date  -Hour 0 -Minute 0 -Second 0 -uformat "%d/%m/%Y %H:%M:%S"
$yesterday00 = $yesterday | Get-Date -Hour 0 -Minute 0 -Second 0 -uformat "%d/%m/%Y %H:%M:%S"


Invoke-Command -ComputerName xxx -Scriptblock {
    Get-ChildItem -Path "xxx" -Recurse | 
        where-object {$_.mode -notmatch "d"} |
        where-object {$_.lastwritetime -gt $yesterday00 -AND $_.lastwritetime -lt $today00 } |
        Get-ChildItem -name |
        out-file filelist.log
}

Someone can help me? Thanks :)

VertigoRay
  • 5,935
  • 6
  • 39
  • 48
eworelinja
  • 11
  • 1
  • 2
    To use local variables (read-only) in a remote command, a simple way is to use the `$using:` scope modifier, e.g. `{$_.LastWriteTime -lt $using:today00}`. Also see [this answer](https://stackoverflow.com/a/63724792/11025476). – AdminOfThings Dec 15 '20 at 13:54
  • it is possible to use the compare without using any variables? in this case of course – eworelinja Dec 15 '20 at 14:15
  • @eworelinja: As an aside: You'll have to [@-mention](https://meta.stackexchange.com/a/43020/248777) someone in order to be notified of a follow-up comment. – mklement0 Dec 15 '20 at 14:39
  • @eworelinja: As for your follow-up question: You can use `(Get-Date).Date` instead of `$using:today00`. If yo have further questions, please create a _new_ question post. – mklement0 Dec 15 '20 at 14:41

0 Answers0