Monday, November 26, 2018

Power Shell: Remove files, subfolders older than X days

Power Shell: Remove files, subfolders older than X days


1. Power shell script to remove files and subfolders older than 30 days from directory "E:\directory\

Get-ChildItem -path "E:\directory\" -recurse | where-object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Remove-Item -Recurse -Force

2. Schedule script: E:\RemoveFiles.ps1

Action: Start a program
Program: PowerShell.exe
Add arguments (optiona): -ExecutionPolicy Bypass E:\RemoveFiles.ps1

No comments:

Post a Comment

Problem with database open ORA-19804, ORA-19809, ORA-03113

1. Try to login to database with SYS AS SYSDBA user. If the instance is idle, run the startup command. 2. If ORA-03113 occured, check the la...