Hi, I'm learning Powershell and came across this script for detecting file locks:
try { [IO.File]::OpenWrite($file).close();$true } catch {$false}
For my purposes I have attempted to tweak it a bit as I just want the file paths returned if they are locked:
get-childitem -recurse | foreach { try { [io.file]::openwrite($_).close() } catch { $_ } }
I have run this with one file opened in Word as a test but I'm not getting any output. I'm probably making an obvious mistake so grateful for any pointers, thanks.