Skip to main content

We had to do a rest on some computers and the reset created Windows.old folders that I need to get removed.  The worklet says it removes the folders but they are not removed.  Any help would be greatly appreciated.

 

$folders = @("C:\Windows.old", "C:\Windows.old(1)", "C:\Windows.old(2)")

foreach ($folder in $folders) {
if (Test-Path $folder) {
Remove-Item -Path $folder -Recurse -Force
Write-Output "Deleted: $folder"
} else {
Write-Output "Not found: $folder"
}
}

 

Hey slammert! 

If the Worklet you’re running reports that the folders were removed, but you still see them on the local device, it likely means there is some sort of error occurring that your code isn’t accounting for. I think this would be a perfect use case for implementing a try/catch and ensuring that the catch block(s) result in a terminating (non-exit 0) error. Use of a write-error will also likely greatly assist in diagnosing any errors you may be encountering, as Automox's activity log will capture and display these for you! In my experience, most times someone has an issue with deleting a folder, it comes from either a lack of permission or EPP blocking the action. Here's a link to some documentation that will help you make sure that you've allowed-listed the necessary directories.
I hope this helps you get those folders deleted! Please let me know if you have any other questions that I can assist with!


Reply