Avatar of samiam41
samiam41Flag for United States of America

asked on 

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!
PowershellWindows 7

Avatar of undefined
Last Comment
samiam41
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
EXPERT CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of samiam41
samiam41
Flag of United States of America image

ASKER

Got some time to check into this so let me update.
Avatar of samiam41
samiam41
Flag of United States of America image

ASKER

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.
Windows 7
Windows 7

Windows 7 is an operating system from Microsoft. Features include multi-touch support, a redesigned Windows Shell with a new taskbar, referred to as the Superbar, a home networking system called HomeGroup, and performance improvements.

48K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo