Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Powershell: powershell deletes files from N days ago

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Randomly create five pre-2019 files in the C:\ Users\ Administrator\ Desktop\ temp1 directory and delete them. :)

$path= "C:\ Users\ Administrator\ Desktop\ temp1" for {$year1=201 $year2= Get-Random-Minimum 0-Maximum 8$ year= "$year1 $year2" $month= Get-Random-Minimum 1-Maximum 12$ day= Get-Random-Minimum 1-Maximum 28$ filelastwite= [datetime]: Parse ("$year-$month-$day") $filelastwite$filename=-join ([char [] (97.122) | Get-Random-Count 5) (New-Item-name $filename-Path $path-ItemType file) .LastWriteTime = $filelastwite$i++} Write-Host "the following files will be deleted!" (Get-ChildItem-Path $path | where {$_ .LastWriteTime-le (get-date). Adddays (- 3)-and $_-is [System.IO.FileInfo]}) .fullname (Get-ChildItem-Path $path | where {$_ .LastWriteTime-le (get-date). Adddays (- 3)-and $_-is [System.IO.FileInfo]}) .fullname | Remove-Item

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report