I have the following code
$top = Get-ChildItem -File C:\SomeFolder\1\ -Recurse -filter *.evtx
foreach ($file in $top) {
$get = (Get-WinEvent -Path C:\SomeFolder\1\$file -erroraction 'silentlycontinue').count
if ($get -eq '0') {
Remove-Item -Path C:\SomeFolder\1\$file -Recurse -Force
}
}
The problem is that the files that I'm trying to delete are in use by the loop.
The following error appears - "Remove-Item : Cannot remove item The process cannot access the file because it is being used by another process."
I even tried exiting with break but it didn't help.
Any suggestions?
Thanks!