PS script won't delete large file (1gb), only smaller files

Hey Experts.  Weird issue with a PS script.  It shows in the log file that the file(s) were deleted but yet they remain in the directory.  Yes I confirmed the right dir was being referenced and the correct date was being used.  Any reason why remove-item may not delete a file?  It didn't have a problem when I tested it on txt files that were 50k but now that I'm deleting files that are each 1GB+, the file isn't being deleted out.

Small portion of code
$deletedfiles = 0
$files = get-childitem -Path $path
$10days = (get-date).AddDays(-8)

foreach ($file in $files){
  if ($file.LastWriteTime -le $10days){
    remove-item -Path $file.fullname -Recurse -Force
    $log += "Deleted:" + $file.name
    $deletedfiles ++

  }
}
$log += "Deleted: " + $deletedfiles + " Files"

Open in new window


Shows the files as deleted but I verify they are still in the directory:

Deleted:spiceworks-backup-[V7.5.00091]-[2018-10-02].zip
Deleted:spiceworks-backup-[V7.5.00091]-[2018-10-03].zip

Thanks for your time and help!
LVL 9
samiam41Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Looking at the name of the file, you will have to use the -LiteralPath parameter of Remove-Item instead of -Path, because of the brackets in the file name.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oBdACommented:
You're not really testing whether the file actually has been deleted.
Try it like that:
$deletedfiles = 0
$files = get-childitem -Path $path
$10days = (get-date).AddDays(-8)
ForEach ($file in $files){
	if ($file.LastWriteTime -le $10days){
		Try {
			Remove-Item -LiteralPath $file.fullname -Force -ErrorAction Stop
			$log += "Deleted:" + $file.name
			$deletedfiles ++
		} Catch {
			$log += "NOT Deleted:" + $file.name
			$log += "Error:" + $_.Exception.Message
		}
	}
}
$log += "Deleted: " + $deletedfiles + " Files"

Open in new window

samiam41Author Commented:
Got some time to check into this so let me update.
samiam41Author Commented:
Once I used the switches that @footech suggested in his post, it worked.  I did try out oBdA's script and it worked as well.  Thanks to you both for your help, time and scripts.  Always appreciated.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.