# Delete Bulk Files based on age and exclude certain files with specified characters

**URL:** <https://forums.powershell.org/t/delete-bulk-files-based-on-age-and-exclude-certain-files-with-specified-characters/17119>\
**Category:** PowerShell Help\
**Created:** [July 20, 2021, 1:00am UTC](https://forums.powershell.org/t/delete-bulk-files-based-on-age-and-exclude-certain-files-with-specified-characters/17119 "2021-07-20T01:00:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Widelk](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@Widelk](https://forums.powershell.org/u/Widelk)\
**Post date:** [July 20, 2021, 1:00am UTC](https://forums.powershell.org/t/delete-bulk-files-based-on-age-and-exclude-certain-files-with-specified-characters/17119/1 "2021-07-20T01:00:32Z")

</div>

Please help me:

I have a task to delete files from shared location on the network. Here is the breakdown.

- Shared location: \path\to\folder
- Doc type to delete: Excel
- Time period: modified files 2 years older and does not contain facebook in the excel name ext
- Validate prior to delete with validation report

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 20, 2021, 2:37am UTC](https://forums.powershell.org/t/delete-bulk-files-based-on-age-and-exclude-certain-files-with-specified-characters/17119/2 "2021-07-20T02:37:11Z")

</div>

Widelk,  
Welcome to the forum.

What you described above is a very achievable task. What’s your question?

> [@Widelk](#):
>
> Please help me:

What exactly do you need help with?

The cmdlets you might use to accomplish this task could be

> **[Get-ChildItem (Microsoft.PowerShell.Management) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.4&viewFallbackFrom=powershell-7.1)**
>
> The Get-ChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers and use the...

> **[Where-Object (Microsoft.PowerShell.Core) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/where-object?view=powershell-7.4&viewFallbackFrom=powershell-7.1)**
>
> The Where-Object cmdlet selects objects that have particular property values from the collection of objects that are passed to it. For example, you can use the Where-Object cmdlet to select files that were created after a certain date, events with a...

> **[Get-Date (Microsoft.PowerShell.Utility) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-date?view=powershell-7.4&viewFallbackFrom=powershell-7.1)**
>
> The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. Get-Date can format the date and time in several .NET and UNIX formats. You can use Get-Date to generate a date or time character string, and then...

> **[Remove-Item (Microsoft.PowerShell.Management) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-item?view=powershell-7.4&viewFallbackFrom=powershell-7.1)**
>
> The Remove-Item cmdlet deletes one or more items. Because it's supported by many providers, it can delete many different types of items, including files, folders, registry keys, variables, aliases, and functions.

Please always read the complete help topic of the cmdlets including the examples to learn how to use them.

If you already have some code you just got stuck with you’re very welcome to share this code here along with the error messages if there are some and an explanation what’s not working as expected and we will be happy to try to help you.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:23pm UTC](https://forums.powershell.org/t/delete-bulk-files-based-on-age-and-exclude-certain-files-with-specified-characters/17119/3 "2024-05-16T20:23:48Z")

</div>


