Stop-Process -Name explorer -Force Start-Process explorer.exe You know the lock is caused by Explorer (e.g., an image or video file preview stuck open). 2. Finding the Culprit: Identifying the Locking Process PowerShell can't directly break a lock without help, but it can tell you who has the lock. For this, we use the Handle tool from Sysinternals (Microsoft’s official utility suite).

A locked file is blocking a critical automated deployment or build script, and you're willing to risk the owning process failing. 5. A Complete PowerShell Unlock Function Here’s a function that combines detection and safe unlocking:

This is useful for scripts that need to wait until a file is free (e.g., a backup script waiting for a database to release a log file). Warning: This is risky. Do not run this on your C: drive.

Run this PowerShell one-liner to find which process is locking C:\path\to\your\file.pdf :

Always save your work before force-unlocking files. A forced handle close is like unplugging a hard drive—it works, but data loss is possible.