Skip to content

Instantly share code, notes, and snippets.

@philipmat
Created July 2, 2021 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipmat/2b60f7480d76cc8158df18fbce28ea5b to your computer and use it in GitHub Desktop.
Save philipmat/2b60f7480d76cc8158df18fbce28ea5b to your computer and use it in GitHub Desktop.
Finds process that locks a given file
[cmdletbinding()]
param(
[Parameter(Position=1, Mandatory = $true)] # Position = 1 allow passing without specifying -FileOrFolderPath
[String] $FileOrFolderPath
)
If((Test-Path -Path $FileOrFolderPath) -eq $false) {
Write-Warning "File or directory does not exist."
}
Else {
# can run openfile directly in powershell, don't need to run through
$LockingProcess = openfiles /query /fo table | Select-String "$FileOrFolderPath" -SimpleMatch -AllMatches
Write-Host $LockingProcess
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment