Notifications
Clear all
BugOverflow
1
Posty
1
Users
0
Reactions
847
Widok
0
15/03/2021 11:11 am
Topic starter
example script
1 Answer
0
15/03/2021 11:16 am
Topic starter
1. Cleanup.ps1
$Folder = "C:ToBackup" $Daysback = "-7" Add-Content C:logsdelete_log.txt "Cleanup started $((Get-Date).ToString())" Get-ChildItem $Folder -Recurse -Force -ea 0 | ? {!$_.PsIsContainer -and $_.LastWriteTime -lt (Get-Date).AddDays($Daysback)} | ForEach-Object { $_ | del -Force $_.FullName | Out-File C:logsdelete_log.txt -Append } #Delete empty folders and subfolders Get-ChildItem $Folder -Recurse -Force -ea 0 | ? {$_.PsIsContainer -eq $True} | ? {$_.getfiles().count -eq 0} | ForEach-Object { $_ | del -Force $_.FullName | Out-File C:logsdelete_log.txt -Append }
2. Task Scheulder
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -ExecutionPolicy Bypass –NoProfile –Command "& {Cleanup.ps1; exit $LastExitCode}" > C:logs.log