Powershell Unlock File 【2026 Edition】

function Test-FileLock { param([string]$FilePath) try { $file = [System.IO.File]::Open($FilePath, 'Open', 'Read', 'None') $file.Close() return $false # File is not locked } catch { return $true # File is locked } } Test-FileLock "C:\locked.docx"

# Graceful stop (sends close signal) Stop-Process -Id 8764 Stop-Process -Id 8764 -Force powershell unlock file

You can use PowerShell to call handle.exe with the -c flag to forcibly close a file handle: powershell unlock file

Now you can stop the offending process gracefully or forcefully: powershell unlock file

Here’s a practical look at how to unlock files using PowerShell, from simple workarounds to advanced force-unlocking. Before diving into complex scripts, the most reliable PowerShell "unlock" is restarting the explorer.exe process. File locks often come from Windows Explorer's thumbnail previews or folder indexing.

x