0
我見過類似的問題,但我決定發佈,因爲我還沒有看到一個持有我正在尋找的細微差別。以不同的時間間隔與Powershell刪除文件
我正在尋找一種方法來添加一個子句,留下孤獨的空文件,然後用戶維護的某些文件。
- 留下任何和所有的空文件夾單獨
- 忽略指定的文件夾和文件類型
到目前爲止,我有這樣的:
Start-Transcript C:\Temp3\filecleanup.log -Append
$folder_path = "[[-Path] <String[K:\]>"
# replace -90 with days before current date to be deleted
$1m = "-30"
$3m = "-90"
$6m = "-180"
$12m = "-360"
$18m = "-540"
$curr_date = Get-Date
#script for 30 days
$del_date1m = $curr_date.AddDays($1m)
Get-ChildItem $folder_path -Recurse [-Exclude <file folders, Applications,
*.bat>] | Where-Object { $_.LastAccessTime -lt $del_date1m } | Remove-Item -
Force -Verbose
#script for 90 days
$del_date3m = $curr_date.AddDays($3m)
Get-ChildItem $folder_path -Recurse [-Exclude <file folders, Applications,
*.bat>] | Where-Object { $_.LastAccessTime -lt $del_date3m } | Remove-Item -
Force -Verbose
#script for 180 days
$del_date1m = $curr_date.AddDays($6m)
Get-ChildItem $folder_path -Recurse [-Exclude <file folders, Applications,
*.bat>] | Where-Object { $_.LastAccessTime -lt $del_date6m } | Remove-Item -
Force -Verbose
#script for 360 days
$del_date1m = $curr_date.AddDays($12m)
Get-ChildItem $folder_path -Recurse [-Exclude <file folders, Applications,
*.bat>] | Where-Object { $_.LastAccessTime -lt $del_date12m } | Remove-Item
-Force -Verbose
#script for 540 days
$del_date1m = $curr_date.AddDays($18m)
Get-ChildItem $folder_path -Recurse [-Exclude <file folders, Applications,
*.bat>] | Where-Object { $_.LastAccessTime -lt $del_date18m } | Remove-Item
-Force -Verbose
Stop-Transcript
你檢查過腳本嗎? – tukan