wbcintsol
asked on
powershell where subfolder contains string
Hi
I need to write a powershell script to remove files older than a certain date but only from sub folder with the name "working" in it
I have found the code below but just need to modify for the folder name
any help is greatly appreciated
code from - http://www.winblogs.net/index.php/2009/10/01/delete-files-older-from-in-powershell/
a
I need to write a powershell script to remove files older than a certain date but only from sub folder with the name "working" in it
I have found the code below but just need to modify for the folder name
any help is greatly appreciated
code from - http://www.winblogs.net/index.php/2009/10/01/delete-files-older-from-in-powershell/
a
Function GetOldFile
{
$Days = "0"
$TargetFolder = "d:\"
if (Test-Path $TargetFolder)
{
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.john -recurse |Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{write-host "Deleting file $File" -foregroundcolor "Red"; Remove-Item $File | out-null}
}
Else
{Write-Host "Folder $TargetFolder doesnt exist! Recheck the folder path!"}
}
GetOldFile
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER