Powershell delete folders older than 30 days Apr 4, 2023 · PowerShell allows us not to only delete a single file, but even an entire directory or a group of files based on specific criteria. ie. To delete files older than a certain number of days in PowerShell, you can use the Get-ChildItem cmdlet to retrieve a list of files, filter out files based on the LastWriteTime property, and then use the Remove-Item command to delete the files. I want to leave any profile that does not have a creation date older than 30 days. Sep 1, 2019 · I want to delete all types of Files from below folder structure which is older than 30 Days. tried to … Nov 30, 2020 · Im a beginner in coding and I need help with one of my very first self coded tools. Aug 8, 2024 · Deleting files older than 30 days can help you manage disk space and keep your directories organized. If you run the script the first time you can add the “-WhatIf” parameter after Remove-Item command. Also looking for it to dump oto a log file with all the file… Apr 5, 2021 · By compressing the files you can save a lot of storage space. txt refere_02012021. By using PowerShell, you can identify files older than any date you choose. Jan 27, 2024 · What is the procedure for automatically archiving all emails older than 30 days in the Deleted Items folder in a mailbox with an Exchange Online P2 license? Because I get this email daily and it is quite important: Your mailbox folder "\\Deleted… Learn how to write a PowerShell function that deletes files from folders and subfolders that are older than 30 days. So I used below PowerShell Script. Hope this is what you were looking for Dan (the script got messed up so use the attached file!!) Message was edited by: a2alpha Preferably the script would use a reference file for the folder path and desired aging limit. log* files older than 30 days. Jan 15, 2025 · This article provides a script to retrieve profile age and optionally delete aged copies. This then leaves us with a collection of objects that were created more than 5 days ago, which we pass to Remove-Item. Jan 18, 2021 · The script below I found and tried to use this to automatically monitor a folder en delete files older then 2 days. DD in the beginning of the folder name if it’s 31+ days older than today’s date. On Windows 10, you can use Command Prompt and Task Scheduler to automatically delete files older than a certain number of days to free up space and keep Oct 21, 2022 · I’ve been asked by my organisation to delete files in the recyling bin for all users which are older than 30 days. We will introduce all the possible ways in this passage. This PowerShell code demonstrates how to use the Get-ChildItem and Remove-Item cmdlets to identify and remove old files. But if I use recurse, it includes all files matching the filter in the sub folders. You can save it as a file with a . Using Retention policies in the Exchange admin center, create a rule that quickly deletes all Outlook emails older than X days. This seems like it would be a common script, but a lot of ones i Feb 3, 2021 · OS: Windows server 2012 R2 I have hundreds of text files which are created on daily basis in a folder with following naming scheme refere_02022020. Delete Files in Folder Older than a Date This script offers a solution for managing file cleanup based on your specified date. My one complaint is that I never found a way to preserve the folder structure if you were moving files. Use caution and double-check your commands to avoid unintentional data loss. This script should check if files were removed 30 days ago or are in recycle bin longer and then remove them. I just want to add a simple IF statement to say "There are not folders older than 30 days" if there are not any. May 6, 2015 · I have a directory that needs to be cleaned out of old files every 30 days and I need to log the files that are deleted. A quick Google search yielded many options. You can use Windows task scheduler to automatically delete files older than a number of days. However I want to keep the latest file for each device even if it is older than 15 days. ps1 extension and then run it: Jan 7, 2023 · Error Logs 1-7 are older than 30 days and should be moved to the Archived folder and after 90 days, it’ll be deleted. Then take those files and add them to a . Dec 13, 2023 · Powershell Recursively List or Delete Files older than 30 days include all files in folders in the subtree regardless of when the folder was modified Asked 1 year, 11 months ago This PowerShell script automatically deletes files older than X number of days (90 days, for instance) when executed. Each client has their own folder in that directory. The general idea would be to run the script periodically to clear up space on some sites with big files. Jun 14, 2025 · Learn how to create PowerShell scripts to automatically delete files older than 30 days. com. I have tried various examples but they are not doing what I expect. Mar 26, 2020 · I've recently taken up the task to clean my NAS and other storage devices of files not touched in over 6 months to clear up storage space. Whether you’re a beginner looking to build your first script or an experienced administrator seeking best practices, this comprehensive tutorial will serve as a valuable resource. PowerShell Script to Zip and Archive Old Files Here is a sample PowerShell script to archive files older than 30 days Over the weekend, a colleague of mine approached me and asked about a method to delete log files over a specific age with a specific file extension on Windows Server. Learn to automate file management and keep your directories organized effortlessly. Apr 20, 2022 · I would like to delete all files older than say 14 days, but always keep the one with the latest epoch timestamp per device. Feb 13, 2009 · The problem in this case is that ForFiles takes a parameter in *days* (/d) and in my case I really want to delete files older than 18 *hours*. Jun 25, 2025 · One common and highly practical task is deleting files older than a specified number of days. This example will use PowerShell to delete files older than 30 days. For each of those things that are older than 30 days we delete them, and anything inside them. Dec 13, 2021 · This guide includes PowerShell scripts to review files older than 30 days, and delete them with detailed output information. It works fine and looks like: There's a group policy for this. The contents are deleted but t… Learn how to write a PowerShell function that deletes all files and folders older than 30 days. g. Learn how to use PowerShell and Task Scheduler to automatically delete files older than 30 days, simplifying file management and cleanup. Customize the folder path and number of days according to your needs. Here's a code snippet to achieve that: Sep 16, 2021 · In this article, I will explain how to use PowerShell to delete files older than x days from your systems. I need to search each Recycle Bin folder and delete files that are older than 30 days. To automate this, create a service account with logon as a service right and configure a scheduled task to run this in a schedule. It provides an efficient way in Windows PowerShell to delete files older than some days, ensuring that only outdated content is removed. Jul 20, 2021 · To list recursively in a share/FileDir, you need to call it recursively. Jul 19, 2013 · I found the following powershell script that can almost do this, however, the problem with this script as it is currently written is that if the folder is older than 30 days it will delete the folder and all data in it, even if that data is only a day old. Syntax of Dec 12, 2024 · Here’s a script to delete files older than 30 days in a specified directory. A batch file contains a series of DOS (Disk Operating System) instructions that automate routine tasks. I have the following script, though when run, files are not deleted. Dec 9, 2019 · So far I have found nothing that addresses my goal. Apr 1, 2025 · Learn how to delete user profiles older than 30 days using PowerShell with automated scripts to free up space and manage system performance efficiently. This is particularly useful for automating cleanup tasks on your Windows system or server. Copy Move Files Older or Newer than X number of days By Steve in Batch Scripts and PowerShell, Microsoft, Microsoft Server 2016, Microsoft Windows 10, Microsoft Windows Server 2008 Tag copy, days, maxage, minage, move files, newer, number, older, Robocopy, Windows Dec 24, 2012 · The --lt (less than) operator is then used to compare the CreationTime property of the objects with Get-Date (the current date) subtract 5 days. Then the script would clean that path of files older than the aging limit. Sep 17, 2025 · Looking for an easy way to delete old files in SharePoint Online? Use this guide to clean up files older than a certain date using PowerShell! Dec 14, 2022 · It doesn't delete folders and files older than 30 days while protecting folders and their contents for those added to exclusions. Get step-by-step instructions and example code. Mar 24, 2018 · I’m trying to run a powershell script to delete ALL the contents of a folder and subfolders older than a month. Learn how to clean up unwanted files and save disk space! Mar 21, 2024 · Learn how to remove files in a folder that are older than a certain date using PowerShell. Here’s an example command that removes files that are older than 30 days: Let’s break down this command: Mar 20, 2017 · I am trying to delete all files in a directory and all files in its sub-directories older than 30 days, leaving all folders intact. using following PS CMD to Delete contents for other tasks Function Move { #Moves all files older than 31 days old from the Source folder to the Target Get-Childitem -Path "E:\\source" | Where-Object { $_. Jun 18, 2021 · Hi I enabled Computer Configuration\\Administrative Templates\\System\\User Profiles\\Delete User Profiles Older Than xxx GPO and apply to Windows 10 PCs. I need the PowerShell script to delete/remove items older than 30 days from redirected RecycleBins. For any folders older than XX days, I want to zip that folder into a file and then delete the folder. This sounded like an excellent task for PowerShell and the Windows Task Scheduler. Use PowerShell to efficiently manage disk space and automate file cleanup on your computer. $limit = (Get-Date). Dec 27, 2023 · Here is the PowerShell command structure for deleting files older than a set number of days recursively under a base folder path: Get-ChildItem C:\Folder -Recurse | Where-Object {$_. Expecting a single command which I can use by adding a pipe sign in the above command. This blog post provides step-by-step instructions and example commands to help you automate this task. May 15, 2025 · In this tutorial, I’ll show you how to create PowerShell scripts that can identify and delete files older than a specified number of days with particular extensions. This script will tell us ,the count of folders inside the ccmcache older than X days which will help us to clean the content. Feb 2, 2024 · Here, we have a directory C:\test_folder1, and we will show you how to delete all files older than X days in that directory. Jun 30, 2025 · You can delete files older than 30 days with PowerShell, and there are other solutions to delete these files. We have a couple locations with Roaming Profiles & Redirected folders to file servers and as we know, users are great at clearing their RecycleBins and using it to store files. This is the script I will be using: Jul 30, 2018 · Robocopy. I found the script through which i can delete locally but need a script for remote shadow copy deletion. This question seems to have been asked to death online and I have In PowerShell, you can delete files older than a specified number of days by using the `Get-ChildItem` and `Remove-Item` cmdlets together. Bob, over the last 5 years, has sent approximately 10,000 messages to this user and I want to nuke them all. I am trying the below code but is not working: I want to run a scheduled task every day that checks a file directory and delete all files older than 30 days, EXCEPT for 1 specific . Follow our easy instructions to create and schedule your script today. Nov 21, 2016 · How to effectively reduce the IIS log files size on disk and automatically cleanup those older than a certain date with a batch file and a Scheduled Task. I am able to come out with regex to sort the epoch dates, but I do not know how to approach the logic for grouping the hostnames. This is great when cleaning up shared drives or temporary file locations. Aug 27, 2015 · Description This Powershell script will delete files older than (number of days you choose) and will look in the root folder (that you designate) as well as all sub folders. Here we need to check if the date is greater than 30 days before deleting the files. AddDays(-30)} | Remove-Item A folder contain n number of files, in that i want to delete only "Tcp" related files, that too which are older than 30 days, there will be lot many files in the name "Tcp". Oct 26, 2009 · So to start with run it from Powershell with . While Storage Sense is limited to these two folders, my script allows you to specify any directory and the number of days to wait before deleting a file. Remove the “-Whatif” to make the script delete the identified files Aug 3, 2022 · Learn how to delete files older than X days (say 7, 10, 30, etc. In this video, I’ll show you how to use Windows Task Scheduler along with a simple PowerShell script to automatically delete files older than a certain number of days from any folder you choose Sep 17, 2025 · This will compress all files in the source path C:\Backup into a ZIP file called OldFiles. ps1 30 Which will check for snapshots older than 30 days before today and then ask for confirmation to commit. MM. It doesn't seem to recognize the CreationTime on the profile, even though I can visually verify the date is within 30 Oct 3, 2021 · I n this tutorial, we’ll learn how to delete folders older than a specific number of days using the FORFILES command in a batch script. May 2, 2022 · Thanks to Microsoft breaking the "Delete user profiles older than a specified number of days on system restart" GPO and not fixing it after all of these years, I need a script that deletes old user profiles. In order to do that, we have to get the current date with Get-Date, subtract 30 days, and then grab everything less than (older than) the resulting date. if I have folders called 1000, 1001, 1002, I want to end up with 1000. This guide provides an in-depth exploration of how to craft a robust PowerShell script that deletes files older than X days. Most of the scripts that I’ve found will delete files/folders that are older than 30 days (based on last accessed or date modified); this won’t work as the user Learn how to write a PowerShell function that deletes files older than 30 days in a user-defined folder without deleting the folders. Here's how to do it in simple steps. Aug 21, 2025 · For the following example, I want to show all files older than 30 days. I also want to delete files in specific sub-directories of the source that are over a certain date, for example 30 days, but I want to be absolutely sure that they've successfully been archived to the SFTP server. To delete folders older than a certain number of days in PowerShell, you can use the Get-ChildItem cmdlet to retrieve a list of folders, filter out folders based on the LastWriteTime property, and then use the Remove-Item command to delete the folders. Jan 12, 2017 · Hi I’m looking for a power shell script that will delete all files older than 120 days but not folders. This process would be set to run once a day via Task Scheduler. I checked the… For each folder we find with that name we pull a directory listing for whatever is inside that folder, and then select only the things older than 30 days. You can use it to cleanup old logfiles or other things. txt someothername. Applies to: Windows Server 2016 and later versions, Windows 11, Windows 10 There's a Group Policy "Delete user profiles older than a specified number of days on system restart" to delete aged copies of user profiles. Mar 15, 2024 · Contents: How to Delete a User Profile in Windows Manually? GPO: Delete User Profiles Older Than a Specified Number of Days Delete Old User Profiles with PowerShell Script Jun 13, 2020 · I’ve got a macro that pulls data for files in a given path older than N days. But compressing files manually on a daily basis is one tedious job! Here’s a solution by power shell script which will compress the files older than x days and delete the original files post verifying the creation of compressed zip file. Learn how to use the different filter option and how to remove folders with PowerShell. I had this one that I thought would work but did not. I have been able May 30, 2021 · Hello All, I’m trying to prepare powershell script which removes files from recycle bin. Sep 17, 2025 · Delete All Versions Older than 30 days in a SharePoint Online Library Below is a PnP PowerShell script to delete all versions of SharePoint Online documents older than 30 days. 0; slower PS v2. I want to delete all files older than x days with a certain file filter. 0 compatible functions are given at the end of this article. Oct 24, 2019 · I'm using PowerShell script to delete folders which are older than x days. I can use 7zip cmd line or the native windows compression. Jun 9, 2014 · Over the last few articles I’ve been demonstrating ways to leverage PowerShell scripts with Group Policy. You may need to catch up to fully understand everything I’m doing in this article, which uses a PowerShell computer start up script to remove old user profiles. Feb 22, 2024 · Learn how to write a PowerShell function that deletes files older than 30 days in a given directory. txt I want to delete text files older than 1 month but only those files that begins with refere or dynamic . Apr 13, 2020 · 2 I have scripts in both PowerShell and Batch file where in it will deleted all the files older than X days from the root folder and inside the sub folders as well from one computer, but I am looking for script where it will delete the files older than X days from multiple servers using one script. txt dynamic_02012021. , using Command Prompt and PowerShell, and here's how on Windows 11. Mar 26, 2015 · If you have a requirement to cleanup older than 30 (or any number of days), days of folders and files from any designated location, you can do it via SQL Server Agent Job. Unfortunately, this didn't remove old data folders in C:\\user. Jump to page sections Target specific directory only Recursively delete from all log folders Here are a few short, simple PowerShell code examples on how to delete old IIS logs (Internet Information Services logs), that are well-suited for being run as a scheduled task on a server. May 23, 2023 · I’d like to delete the folder (and all subfolders/files) based on the YYYY. I have added the attempted code in the main question as part 2. A timestamp stored in the registry has been used since Windows 10, Windows Server 2019 May 8, 2023 · To delete files older than 30 days on Windows 10, use the “ForFiles” command. Jun 17, 2022 · You can quickly delete files older than 7, 30, 45, 60 days, etc. AddDays (-30))} | Remove-Item But how to add Jul 22, 2021 · I'm using this code to delete files older than 30 days Sep 19, 2016 · I am trying to delete all files in subfolders of a given folder without deleting the subfolders themselves. I wrote this script, but it's not working. For some reason the below script is not working. Includes 5 proven methods with logging, scheduling, and error handling. This is a good PowerShell script to delete files older than X number of days, but we would like to delete multiple files saved at different locations with different number of days for each path. I once cleared up over 50GB on a client’s machine with a version of this. I made this script inspired by Windows’ Storage Sense feature which automatically deletes older files from the Recycle Bin and Downloads folder. LastWriteTime -lt (Get-Date). C:\\Clients|Client1 In each client’s folder is a folder called Recycle Bin. Basically the May 24, 2022 · Delete using the Auto-archive option in Outlook. But it is not deleting any file. E. The command is: ForFiles /p “C:\path\to\folder” /s /d -30 /c “cmd /c del /q @file”. Sep 23, 2020 · Below command, delete files older than 30 days Get-ChildItem –Path "C:\path\to\folder" -Recurse | Where-Object { ($_. zip stored in the C:\Archives folder. Jun 1, 2020 · I’ve been trying to work on a script that will remove any user profiles that are older than 30 days on some of the computers in my organization. Learn how to delete files that are more than 30 days old in a local folder using PowerShell. txt dynamic_02022021. Sep 23, 2020 · Since you only want to remove files, you should use the -File switch on the Get-ChildItem. • With “-Path”: It will get an instance of a directory or file (with file properties like LMT) in the specified path. AddDays(-31)} | Nov 6, 2023 · Hi, I've made a script that deletes files in folders and subfolders. Oct 30, 2023 · This example will use PowerShell to target files in two different folders, ensuring they’re older than a given date before deletion. Change the number of days that you want to delete content older than. I don't want to delete ALL messages older than 30 days. days) automatically using Storage Sense or ForFiles command line in Windows 11/10. I want to delete all messages from bob@example. The check to see if it is a container appears to work if you do not want to delete the folder, but it still allows the script to Dec 13, 2010 · This is a simple PowerShell script which deletes Files older than some days. Feb 21, 2024 · Use the Remove-item cmdlet in PowerShell to Delete Folders. * to delete everything older than x days or put the file extension if you only need to delete files with certain file extensions. Discover how to effortlessly utilize a PowerShell script to delete user profiles older than 30 days, streamlining your system management with ease. I am learning PowerShell so I am having difficulties stringing together multiple where parameters. May 9, 2022 · I want to clean up the files and folders of a FTP server which is used by my customers and want to use 3 steps: Remove files with a specific file extension or name older than x days Remove all files older than x days in specific folders Remove empty folders except when the folders has a specific name This is the script I created: Step 1 and 2 are working, but step 3 is not deleting any folders Jul 31, 2023 · The above assumes that the folder path is D:\My Scripts and you want to delete files older than 30 days. It will not seem to find ANY files unless I use recurse. Unfortunately I can’t find an option to delete emails after X days within the public folder’s Folder Assistant… is there a way to create this rule in Exchange Powershell? FYI - Outlook AutoArchive will not work, this needs to be setup on a server/public Jun 8, 2021 · The script below finds folders older than 30 days. Jul 10, 2024 · How to Delete Files Older Than a Specified Number of Days Using PowerShellFor those who might be dealing with old log files or any content that’s been sitting untouched for the last 30 days, the script is the answer you’re looking for. Sep 9, 2008 · The two command lines delete files or folders older than 2 days. txt file I have saved there. If you’re looking for a comprehensive guide on how to use PowerShell to delete files based on their age, whether they’re older than 1 day, 5 days, or any amount of days, you’ve come to the right place. The basic structure Aug 1, 2020 · You can easily modify this script to delete files instead of folders, and you can use *. I use these functions to delete files older than a certain date. PowerShell Remove-Item cmdlet makes it easier to remove files from the system. # Enter a num… Jun 11, 2019 · I am looking to delete all files from azure storage blob which are older than 'x' days. The following command gets all the files in the C:\test_folder1 directory. I made a small script, which deletes files based on if they are older than date x (lastwritetime). I created a policy under group policy management → computer configuration → policies → admin templates → system → system sense → configure storage sense to recycle bin cleanup threshold and set this to 1 day to test. I'm trying to come up with a solution to delete stale profiles in our Windows environment. I'm in need of some help in getting the PowerShell script below working. And lastly delete those files from the original folder. Nov 17, 2021 · I've been working on a script below for this, but I cannot get it to work quite right. LastWriteTime -lt (get-date). Jan 2, 2019 · It works well. Mar 16, 2023 · Yet one question, How can I delete also the folders older than 14 day’s? Now only the files in these folders are deleted. Delete user profiles older than a specified number days on system restart under Computer Configuration\Administrative Templates\System\User Profiles Oct 5, 2022 · So, if you need to delete files older than a certain number of days, try the solutions we’ve covered. Each operating system provides built-in tools for this task, allowing you to automate the process with scripts or scheduled jobs. Once identified, I attempted to run a batch file to delete files from the same date specification, but yet a UNC error? May 3, 2018 · I wish to run a script daily that will delete folders and respective files in it which are older than X days (for my webcam recordings). The "Whatif’ switch has been added to the end of the code so that you can test the script and see the results without actually deleting anything. Jan 5, 2024 · Let’s explore an example that demonstrates how PowerShell can efficiently remove files older than a specified date, offering a practical solution for file cleanup. Mar 21, 2024 · To remove files that are older than a certain date, we will use the Get-ChildItem cmdlet to get a list of files in the folder, and then filter them based on their LastWriteTime property. Jul 23, 2025 · Recently, one of my clients wanted to list down old files from a shared drive in their New York office. zip, 1002. I once again turn Sep 17, 2025 · Keep your system tidy by deleting all files older than x days using PowerShell script. zip, 1001. Does anyone have a working PowerShell script to delete file versions older than 30 days from a SharePoint list? I found a working script to remove previous X versions, but not one that works with both SharePoint Online MFA and dates. But it still deletes all profiles in the C:\Users folder. And did you know it’s also possible to only delete a file if it exists, files that are older than x days, or delete files based on a wildcard pattern? Oct 15, 2015 · I am trying to find all OST files on a network drive that are older than 29 days. Oct 10, 2022 · 0 If you just want to delete files older than 30 days in C:\FullDir (and all subdirectories), then consider using forfiles instead: forfiles /p "C:\FullDir" /s /d -30 /c "cmd /c del @path" (I would recommend first testing that it does what you want it to do, by using echo instead of del) Jul 23, 2021 · I am trying to write a script that would delete all files in a directory older than 15 days. In this tutorial, I will show you how to find files older than a specific date using PowerShell, along with some examples, such as finding files older than 5 years or 30 days. Sep 23, 2020 · Delete files older than 30 days under S3 bucket recursively without deleting folders using PowerShell Asked 4 years, 7 months ago Modified 4 years, 7 months ago Viewed 2k times. /snapremdate. Change “30” to the number of days you want and the folder path. I have a batch file that deletes log files over 30 days old, but I don't think it's a safe way to delete important files. AddDays (-15) $path = "xxxx\path" # Delete files older than the $limit. ZIP folder in a different network location. Feb 6, 2023 · You can use PowerShell to free up space and keep things organized by only deleting files older than a certain number of days in any folder — here's how to do it on Windows 10. Nov 12, 2021 · Hi, I am trying to achieve the following: Count the number of log files in several file paths then save the number to a txt file (along with date/time) Delete log files older than 90 days Count the number of files in t… PowerShell is great for moving or deleting files older than X days. Jul 18, 2022 · Hi Admin, i would like to know how to delete shadow copies through remotely which are older than 30 days. This script requires administrative privileges and should be used with caution. Sep 11, 2019 · Hello, I am looking to setup a rule to delete all emails in a specific public folder “Customer Service” that are older than 30 days. zip. Let’s use the below script to archive and delete logs in that order. Windows file explorer does not have an option to delete files older than x days, we have to manually remove files from the system. Create an Outlook rule to delete emails older than a certain date from a specific folder. Dec 3, 2017 · Here is how to can delete files older than certain days using three different methods, including File Explorer, Command Prompt and PowerShell in Windows. The PowerShell script to delete files older than a specified number of days uses two key cmdlets: Get-ChildItem to retrieve files from a directory, and Remove-Item to delete those files. It’s leaving behind folders. The problem I experience is that I'm prompted with "The item at G:\\test\\XXX Dec 12, 2018 · Now, I am unable to get a compress command in PowerShell via which I can compress (zip/tar) the server. In order not to keep calculating the reference date 30 days ago, I like to define that in a variable $refDate first. Jun 4, 2015 · 10 This powershell script will show files older than 5 days, 10 hours, and 5 minutes. Jun 26, 2013 · Hey gang, I’ve been trying to form a PowerShell script that will look thru a given folder and find any files older than X days. Feb 26, 2025 · This tutorial provides a step-by-step guide on how to delete files older than N days using Batch Script. Aug 17, 2022 · If I run the code and don’t use the ForEach loop by individually specifying the folder names it works to 7zip the folder (but not delete the folder - I could do this by deleting folders older than 30 days after the 7zip process completes but I guess I wouldn’t be able to tell if the folder (and files under it) were zipped successfully). -d -3 means according to the usage help output on running forfiles /? in a command prompt window: less than or equal to (-) the current date minus the specified days. Note that these functions require PS v3. I want the script to run the same as going to Control Panel > System > Advanced System Settings > User Profiles and deleting them from there. May 3, 2018 · I wish to run a script daily that will delete folders and respective files in it which are older than X days (for my webcam recordings). Jun 12, 2024 · This tutorial explains how to delete all files older than a certain number of days in PowerShell, including an example. I want to make a scheduled process in Windows (specifically, Windows 7) that every 3 hours will delete all the files in all folders older than 24 hours (like the Unix find's -mtime +1). PowerShell Script: Get-ChildItem – Jun 13, 2023 · I need Powershell script to delete log files from log folder path older than 180 days, which can be performed using task scheduler. Unfortunately, delprof2 isn't working anymore due to a dat file that gets updated whenever a windows update gets applied to the endpoint. The input reference file would look something like this: c:\logs\iis\siteA\ 30 c:\logs\job1\ 60 e:\archive\clientA\ 90 Oct 15, 2013 · PowerShell Functions To Delete Old Files And Empty Directories October 15, 2013 5 minute read I thought I’d share some PowerShell (PS) functions that I wrote for some clean-up scripts at work. The following script will list files/FileDir recursively in a file share, and delete the files older than 14 days. The parent directory is C:\\Clients. Dayes set to 90. Dec 7, 2017 · I am trying to delete all files which ar