שואל
Powershell listing files with different creationtime and lastwritetime.

שאלה
-
Goodmorning everyone,
I am trying to create a Powershell script that will list all files in a directory that have not matching CreationTime and LastWriteTime. So far, what I got is the following;
Get-ChildItem -Path C:\MyPath -Recurse | Where-Object {$_.CreationTime -ne $_.LastWriteTime}
So far this is working as I need it to. However, I want to make a change to this script so it will only list the files that have more then 2 seconds difference in the creationtime and lastwritetime.
Does anyone know how to accomplish this?
Thanks and regards!
- נערך על-ידי FTLY יום שישי 24 מאי 2019 06:47
כל התגובות
-
($_.CreationTime - $_.LastWriteTime) -gt [timespan]'0:0:0:2'
\_(ツ)_/
- הוצע כתשובה על-ידי LeeSeenLiMicrosoft contingent staff, Moderator יום שישי 24 מאי 2019 07:36
-
Thanks for your reply, I did try this but it doesn't give any results, while it should do.
PS C:\Users\Test> Get-ChildItem -Path C:\MyPath -Recurse | Where-Object {$_.CreationTime -ne $_.LastWriteTime} | select name,creationtime,LastWriteTime
Name CreationTime LastWriteTime
---- ------------ -------------
Doc1.docx 24-5-2019 08:23:40 24-5-2019 08:23:41
test1.xlsx 24-5-2019 08:18:06 24-5-2019 07:46:40
test2.xlsx 24-5-2019 07:46:40 24-5-2019 08:18:52
PS C:\Users\Test> Get-ChildItem -Path C:\MyPath -Recurse | Where-Object {$_.CreationTime -ne $_.LastWriteTime} -gt [timespan]'0:0:0:2' | select name,creationtime,LastWriteTime
PS C:\Users\Test> Get-ChildItem -Path C:\MyPath -Recurse | Where-Object {$_.LastWriteTime - $_.CreationTime} -gt [timespan]'0:0:0:2' | select name,creationtime,LastWriteTimeThanks
-
-
-
-
Thanks, this is looking more like what I need. This script however will list the documents that have identically CreationTime and LastWriteTime. Can we turn this around so it will list this files that have non-matchin CreationTime and LastWrite time, with a deviation bigger then 2 seconds.
I tried changing the "-" between CreationTime and LastWriteTime in your script, but that doesn't seem to do anything if I change it with -ne for example.
Thanks again for your help jrv.
-
Hi,
Thanks for your reply.
"-lt": Less than
"-gt": Greater than
Maybe you can use "-gt" to solve your issue.
More information, please refer the link below:
https://4sysops.com/archives/powershell-comparison-operators-eq-lt-gt-contains-like-match
Best regards,
Just do it.