Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Files not getting deleted using Powershell

$
0
0

I have written the following script using a post on this forum. The script deletes the files which are older than 15 days:

cls$servers = Get-Content server.txt$limit =(Get-Date).AddDays(-15)$path ="E:\CheckDBOutput"

ForEach ($line in$servers){
Invoke-Command -cn line -ScriptBlock { Get-ChildItem -Path $path -Recurse -Force | Where-Object {!$_.PSIsContainer -and$_.CreationTime -lt $limit }| Remove-Item -Force}}

The script is executing fine without errors, but no files are getting deleted.

Kindly tell me what modification should I do for making this script working. Thanks in advance.


Viewing all articles
Browse latest Browse all 6937

Trending Articles