Check if a certain file has been updated in last X days and error if is hasn't
i need test if file has been updated within last few days (it's updated monthly) , proceed if so, error if hasn't been updated.
i used following check if file has been updated:
get-item c:\temp\junk.txt | where{$_.lastwritetime -gt (get-date).adddays(-7)}
it returns file:
but couldn't work in if/else statement, tried test-path:
$path = "c:\temp\junk.txt" if(test-path -path $path | where{$_.lastwritetime -gt (get-date).adddays(-7)}) { "file exists" } else {“no file” }although returns "no file".
idea i'm doing wrong??
-al h
hi,
here's how i'd that:
if ((get-item c:\temp\junk.txt).lastwritetime -gt (get-date).adddays(-7)) { write-output 'less 7' } else { write-output 'too old' }
don't retire technet! - (don't give yet - 13,085+ strong , growing)
Windows Server > Windows PowerShell
Comments
Post a Comment