Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have shared folder "\\Test\PQR". It has many files. I want to delete only those files which contains 'abc' as part of the filename and those files should be older than 4 days.
How to accomplish this using powershell script ?

Appreciate any help on this.

What I have tried:

Get-ChildItem –Path "\\intranet.barcapint.com\dfs-emea\Group\Ldn\Apps\CMCV\EM\FTPProd\DTU" -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-4)} | ForEach-Object { $_.FullName } > F:\output_DTU.txt

I am not getting how to identify whether file name contains 'abc'.
Posted
Updated 11-Apr-19 0:50am
v2

1 solution

You may try
PowerShell
$_.BaseName -like "*abc*"
as a conditional test for files including 'abc' in their name.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900