Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Deleting X number of days old files through powershell script

$
0
0

Hi All,

I am trying to delete X number of old files through powershell script but in few directories it is prompted with below notification if click yes it will clean all file including latest one also , Kindly assist how I can mitigate this warning or recurse parameter is applicable on all subdirectories. 

The item at Microsoft.PowerShell.Core\FileSystem::E:\test has children and the Recurse
parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to
continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):

Below is the powershell script :

$path = 'E:\test'
Get-ChildItem $path -Recurse |
Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-75))} | Remove-Item



Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images