Powershell 3.0: Returning a list of file names with last write times within the past 24 hours -


i writing script checks, recursively, folders , file names in directory, , returns names , last write times text file. want names of files , folders have been added within past twenty 4 hours.

$date = get-date  get-childitem 'r:\destination\path' -recurse | where-object { $_.lastwritetime -lt $date -gt $date.adddays(-1) } | select lastwritetime, name > 'c:\destination\path\lastwritetime.txt' | clear-host invoke-item 'c:\destination\path\lastwritetime.txt' 

the .txt file invoked blank, which, based on test conditions have set should not case. doing wrong?

you missing logical and. change:

where-object { $_.lastwritetime -lt $date -gt $date.adddays(-1) }  

to

where-object { $_.lastwritetime -lt $date -and $_.lastwritetime -gt $date.adddays(-1) }  

even better use parenthesis, if have used them syntax not have been parsed missing and:

where-object { ($_.lastwritetime -lt $date) -and ($_.lastwritetime -gt $date.adddays(-1)) }  

Comments

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -