Hi, i having the following problem. In a server sometimes after stopping services, one or two files in a directory (most of the time is a dll), get lock by svchost process. I tried to create a powershell script (to use in an Azure Devops job) to find the process that is locking this file but I cann’t find it.
-
I used handle tool. I even list all item to a text file (handle64 > fileproc.txt), and I don’t find that file
-
I used the following code (and nothing)
Get-Process | foreach{$processVar = $;$.Modules | foreach{if($_.FileName -eq $lockedFile){$processVar.Name + " PID:" + $processVar.id}}} -
In Process explorer when I search for that file, I get the process id. Any ideas why in option 1 or option 2, don’t find the locked file?
-
When I try with [System.IO.File]::Open, it throws an error, that is locked. Is that possible to get there the process id?
Thanks