Forum

powershell - select...
 
Notifications
Clear all

powershell - select files modified X hours ago and copy them

1 Posty
1 Users
0 Reactions
849 Widok
0
Topic starter

example script, ps1

1 Answer
0
Topic starter
#select files older than 2 hours
$date = Get-Date
$start_date = $date.AddHours(-2) 

#cleanup destination directory
Remove-Item MY_DESITNATION_DIR* -Recurse

#copy
Get-ChildItem -Path Backup -File |
    Where-Object { $_.LastWriteTime -gt  $start_date } |
    ForEach-Object {
        Copy-Item -Path MY_SOURCE_DIR$_ -Destination 'MY_DESITNATION_DIR' 
    }

Odpowiedź

Author Name

Author Email

Your question *

Preview 0 Revisions Saved
Share: